Skip to content

Commit 81a59ba

Browse files
blake-newmanyyx990803
authored andcommitted
feat: normalize default loader for commonly known postcss langs (#1055)
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 e27a5ce commit 81a59ba

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.
@@ -572,9 +576,11 @@ module.exports = function (content) {
572576
hasInlineConfig: !!query.postcss
573577
}) +
574578
'!'
575-
// normalize scss/sass if no specific loaders have been provided
579+
// normalize scss/sass/postcss if no specific loaders have been provided
576580
if (!loaders[lang]) {
577-
if (lang === 'sass') {
581+
if (postcssExtensions.indexOf(lang) !== -1) {
582+
lang = 'css'
583+
} else if (lang === 'sass') {
578584
lang = 'sass?indentedSyntax'
579585
} else if (lang === 'scss') {
580586
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
@@ -511,6 +511,17 @@ describe('vue-loader', () => {
511511
})
512512
})
513513

514+
it('postcss options', done => {
515+
test({
516+
entry: './test/fixtures/postcss-lang.vue'
517+
}, (window) => {
518+
let style = window.document.querySelector('style').textContent
519+
style = normalizeNewline(style)
520+
expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}')
521+
done()
522+
})
523+
})
524+
514525
it('transpile ES2015 features in template', done => {
515526
test({
516527
entry: './test/fixtures/es2015.vue'

0 commit comments

Comments
 (0)