Skip to content

Commit

Permalink
fix: revert postcss-loader order change
Browse files Browse the repository at this point in the history
The loader used for minification should come first in the rules array
(i.e. execute last, as webpack loaders are executed in reverse order).
  • Loading branch information
haoqunjiang committed Sep 12, 2018
1 parent 714d12a commit b559005
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions packages/@vue/cli-service/__tests__/css.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ test('css.extract', () => {
// does not support mixing config files with loader options.
expect(findLoaders(config2, lang)).toEqual(['vue-style', 'css', 'postcss', 'postcss'].concat(loader))
expect(findOptions(config2, lang, 'css').importLoaders).toBe(3)
// minification loader should be injected after the user-facing postcss-loader
const rule = findRule(config2, lang)
const postcssUse = rule.use.slice().reverse().find(({ loader }) => loader === 'postcss-loader')
expect(postcssUse.options.plugins).toBeTruthy()
// minification loader should be injected before the user-facing postcss-loader
expect(findOptions(config2, lang, 'postcss').plugins).toBeTruthy()
})
})

Expand Down
14 changes: 7 additions & 7 deletions packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,6 @@ module.exports = (api, options) => {
.loader('css-loader')
.options(cssLoaderOptions)

if (hasPostCSSConfig) {
rule
.use('postcss-loader')
.loader('postcss-loader')
.options(Object.assign({ sourceMap }, loaderOptions.postcss))
}

if (needInlineMinification) {
rule
.use('cssnano')
Expand All @@ -147,6 +140,13 @@ module.exports = (api, options) => {
})
}

if (hasPostCSSConfig) {
rule
.use('postcss-loader')
.loader('postcss-loader')
.options(Object.assign({ sourceMap }, loaderOptions.postcss))
}

if (loader) {
rule
.use(loader)
Expand Down

0 comments on commit b559005

Please sign in to comment.