From 57e7db28d5a866ffbc58844e1ab0ae415f06b76c Mon Sep 17 00:00:00 2001 From: Darius Tall Date: Sun, 12 Jun 2016 13:09:20 -0400 Subject: [PATCH 1/2] Add the ability to specify other postcss options --- lib/style-rewriter.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index a212d0a..2bd6398 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -45,27 +45,31 @@ module.exports = function (id, css, scoped) { if (val) { return Promise.resolve(val) } else { - var plugins = options.postcss - ? options.postcss.slice() - : [] + var config + if (options.postcss instanceof Array) { + config = { plugins: options.postcss.slice() } + } else if (options.postcss instanceof Object) { + config = Object.assign({ plugins: [] }, options.postcss) + } + // scoped css rewrite if (scoped) { - plugins.push(addId) + config.plugins.push(addId) } // autoprefixing - if (options.autoprefixer !== false) { - var autoprefixer = require('autoprefixer')(options.autoprefixer) - plugins.push(autoprefixer) + if (config.autoprefixer !== false) { + var autoprefixer = require('autoprefixer')(config.autoprefixer) + config.plugins.push(autoprefixer) } // minification if (process.env.NODE_ENV === 'production') { - plugins.push(require('cssnano')(assign({ + config.plugins.push(require('cssnano')(assign({ autoprefixer: false, safe: true - }, options.cssnano))) + }, config.cssnano))) } currentId = id - return postcss(plugins) + return postcss(config) .process(css) .then(function (res) { var val = { From f9fd01f5410a7117a7bd53ca9dc762258754396c Mon Sep 17 00:00:00 2001 From: Darius Tall Date: Sun, 12 Jun 2016 14:30:38 -0400 Subject: [PATCH 2/2] Fixed usage of postcss --- lib/style-rewriter.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index 2bd6398..3639240 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -45,32 +45,35 @@ module.exports = function (id, css, scoped) { if (val) { return Promise.resolve(val) } else { - var config + var plugins = [] + var opts = {} + if (options.postcss instanceof Array) { - config = { plugins: options.postcss.slice() } + plugins = options.postcss.slice() } else if (options.postcss instanceof Object) { - config = Object.assign({ plugins: [] }, options.postcss) + plugins = options.postcss.plugins || [] + opts = options.postcss.options } // scoped css rewrite if (scoped) { - config.plugins.push(addId) + plugins.push(addId) } // autoprefixing - if (config.autoprefixer !== false) { - var autoprefixer = require('autoprefixer')(config.autoprefixer) - config.plugins.push(autoprefixer) + if (options.autoprefixer !== false) { + var autoprefixer = require('autoprefixer')(options.autoprefixer) + plugins.push(autoprefixer) } // minification if (process.env.NODE_ENV === 'production') { - config.plugins.push(require('cssnano')(assign({ + plugins.push(require('cssnano')(assign({ autoprefixer: false, safe: true - }, config.cssnano))) + }, options.cssnano))) } currentId = id - return postcss(config) - .process(css) + return postcss(plugins) + .process(css, opts) .then(function (res) { var val = { source: res.css, @@ -81,3 +84,4 @@ module.exports = function (id, css, scoped) { }) } } +