Skip to content

Commit 21fc1f9

Browse files
committed
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
1 parent e637c88 commit 21fc1f9

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/loader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const defaultLang = {
2929
script: 'js'
3030
}
3131

32+
const postcssExtensions = [
33+
'postcss', 'pcss', 'sugarss', 'sss'
34+
]
35+
3236
// When extracting parts from the source vue file, we want to apply the
3337
// loaders chained before vue-loader, but exclude some loaders that simply
3438
// produces side effects such as linting.
@@ -556,9 +560,11 @@ module.exports = function (content) {
556560
hasInlineConfig: !!query.postcss
557561
}) +
558562
'!'
559-
// normalize scss/sass if no specific loaders have been provided
563+
// normalize scss/sass/postcss if no specific loaders have been provided
560564
if (!loaders[lang]) {
561-
if (lang === 'sass') {
565+
if (postcssExtensions.indexOf(lang) !== -1) {
566+
lang = 'css'
567+
} else if (lang === 'sass') {
562568
lang = 'sass?indentedSyntax'
563569
} else if (lang === 'scss') {
564570
lang = 'sass'

test/fixtures/postcss-lang.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<style lang="pcss">
2+
h1 {
3+
color: red;
4+
font-size: 14px
5+
}
6+
</style>

test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,17 @@ describe('vue-loader', () => {
507507
})
508508
})
509509

510+
it('postcss options', done => {
511+
test({
512+
entry: './test/fixtures/postcss-lang.vue'
513+
}, (window) => {
514+
let style = window.document.querySelector('style').textContent
515+
style = normalizeNewline(style)
516+
expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}')
517+
done()
518+
})
519+
})
520+
510521
it('transpile ES2015 features in template', done => {
511522
test({
512523
entry: './test/fixtures/es2015.vue'

0 commit comments

Comments
 (0)