From 1a16bc715e80f944687a64a8af76835f7eee6bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dias?= Date: Tue, 24 May 2016 12:32:36 +0200 Subject: [PATCH 1/5] Allow vue-loader to user PostCSS options as object and custom syntax like SugarSS --- lib/style-rewriter.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index cce1e4867..4e1c86b88 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -41,6 +41,9 @@ module.exports = function (css, map) { if (typeof plugins === 'function') { plugins = plugins.call(this, this) } + else if (typeof plugins === 'object') { + plugins = options.postcss.plugins + } plugins = plugins ? plugins.slice() : [] // make sure to copy it // scoped css @@ -81,6 +84,11 @@ module.exports = function (css, map) { } } + // postcss options, for syntax + if (options.postcss.syntax) { + opts.parser = options.postcss.syntax + } + postcss(plugins) .process(css, opts) .then(function (result) { From 0d2b92f6d8f1280165fc0e4f03fed08394cae29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dias?= Date: Tue, 24 May 2016 12:40:55 +0200 Subject: [PATCH 2/5] Fix error reported by eslint --- lib/style-rewriter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index 4e1c86b88..fc18af914 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -40,8 +40,7 @@ module.exports = function (css, map) { var plugins = options.postcss if (typeof plugins === 'function') { plugins = plugins.call(this, this) - } - else if (typeof plugins === 'object') { + } else if (typeof plugins === 'object') { plugins = options.postcss.plugins } plugins = plugins ? plugins.slice() : [] // make sure to copy it From 20a79a8109fd764261f0398d5022d5ee1ec569da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dias?= Date: Tue, 24 May 2016 12:44:46 +0200 Subject: [PATCH 3/5] Better testing of available options to avoid complain about undefined properties --- lib/style-rewriter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index fc18af914..489f6820a 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -40,7 +40,7 @@ module.exports = function (css, map) { var plugins = options.postcss if (typeof plugins === 'function') { plugins = plugins.call(this, this) - } else if (typeof plugins === 'object') { + } else if (typeof options.postcss === 'object' && options.postcss.plugins) { plugins = options.postcss.plugins } plugins = plugins ? plugins.slice() : [] // make sure to copy it @@ -84,7 +84,7 @@ module.exports = function (css, map) { } // postcss options, for syntax - if (options.postcss.syntax) { + if (options.postcss && options.postcss.syntax) { opts.parser = options.postcss.syntax } From b9c08b61e2be17bfde991c854ef6908c97fe4c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dias?= Date: Wed, 25 May 2016 14:38:55 +0200 Subject: [PATCH 4/5] Allow postcss to use a PostCSS options object --- lib/style-rewriter.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index 489f6820a..e1d9c4f6d 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -74,7 +74,8 @@ module.exports = function (css, map) { this.sourceMap && !this.minimize && options.cssSourceMap !== false && - process.env.NODE_ENV !== 'production' + process.env.NODE_ENV !== 'production' && + !options.postcss.options.map ) { opts.map = { inline: false, @@ -83,9 +84,13 @@ module.exports = function (css, map) { } } - // postcss options, for syntax - if (options.postcss && options.postcss.syntax) { - opts.parser = options.postcss.syntax + // postcss options from configuration + if (options.postcss && options.postcss.options) { + for (option in options.postcss.options) { + if (!opts.hasOwnProperty(option)) { + opts[option] = options.postcss.options[option] + } + } } postcss(plugins) From 2597a550b9bed680ee4f7fd45d6774d9873f30f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dias?= Date: Wed, 25 May 2016 14:41:27 +0200 Subject: [PATCH 5/5] Fix error option is undefined --- lib/style-rewriter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index e1d9c4f6d..63ff2b73f 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -86,7 +86,7 @@ module.exports = function (css, map) { // postcss options from configuration if (options.postcss && options.postcss.options) { - for (option in options.postcss.options) { + for (var option in options.postcss.options) { if (!opts.hasOwnProperty(option)) { opts[option] = options.postcss.options[option] }