From 21fc1f92316bee9d987c60ecb96f4f137e42bcaf Mon Sep 17 00:00:00 2001 From: Blake Newman Date: Sun, 12 Nov 2017 22:24:06 +0000 Subject: [PATCH] Feature: postcss extensions to default loader if no loader provided If no postcss loader is provided in vue loader options then default to vue-loader handling This allows you to use vue internal postcss/css handling with known postcss extensions fixes: #942 fixes: #800 fixes: #654 --- lib/loader.js | 10 ++++++++-- test/fixtures/postcss-lang.vue | 6 ++++++ test/test.js | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/postcss-lang.vue diff --git a/lib/loader.js b/lib/loader.js index 217d7bc3d..e4210e3c8 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -29,6 +29,10 @@ const defaultLang = { script: 'js' } +const postcssExtensions = [ + 'postcss', 'pcss', 'sugarss', 'sss' +] + // When extracting parts from the source vue file, we want to apply the // loaders chained before vue-loader, but exclude some loaders that simply // produces side effects such as linting. @@ -556,9 +560,11 @@ module.exports = function (content) { hasInlineConfig: !!query.postcss }) + '!' - // normalize scss/sass if no specific loaders have been provided + // normalize scss/sass/postcss if no specific loaders have been provided if (!loaders[lang]) { - if (lang === 'sass') { + if (postcssExtensions.indexOf(lang) !== -1) { + lang = 'css' + } else if (lang === 'sass') { lang = 'sass?indentedSyntax' } else if (lang === 'scss') { lang = 'sass' diff --git a/test/fixtures/postcss-lang.vue b/test/fixtures/postcss-lang.vue new file mode 100644 index 000000000..0f3255f1f --- /dev/null +++ b/test/fixtures/postcss-lang.vue @@ -0,0 +1,6 @@ + diff --git a/test/test.js b/test/test.js index 51ec6019a..9ee43bfb1 100644 --- a/test/test.js +++ b/test/test.js @@ -507,6 +507,17 @@ describe('vue-loader', () => { }) }) + it('postcss options', done => { + test({ + entry: './test/fixtures/postcss-lang.vue' + }, (window) => { + let style = window.document.querySelector('style').textContent + style = normalizeNewline(style) + expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}') + done() + }) + }) + it('transpile ES2015 features in template', done => { test({ entry: './test/fixtures/es2015.vue'