mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
refactor(style-loader): explicit loaders order on apply function
This commit is contained in:
parent
96bfc40672
commit
d60438df92
@ -28,7 +28,7 @@ export default class StyleLoader {
|
||||
))
|
||||
}
|
||||
|
||||
styleResource(ext, loaders) {
|
||||
styleResource(ext) {
|
||||
const extResource = this.resources[ext]
|
||||
// style-resources-loader
|
||||
// https://github.com/yenshih/style-resources-loader
|
||||
@ -37,31 +37,31 @@ export default class StyleLoader {
|
||||
? extResource
|
||||
: [extResource]
|
||||
|
||||
loaders.push({
|
||||
return {
|
||||
loader: 'style-resources-loader',
|
||||
options: Object.assign(
|
||||
{ patterns },
|
||||
this.resources.options || {}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
postcss(loaders) {
|
||||
postcss() {
|
||||
// postcss-loader
|
||||
// https://github.com/postcss/postcss-loader
|
||||
if (this.postcssConfig) {
|
||||
const config = this.postcssConfig.config()
|
||||
if (config) {
|
||||
loaders.unshift({
|
||||
return {
|
||||
loader: 'postcss-loader',
|
||||
options: Object.assign({ sourceMap: this.sourceMap }, config)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
css(loaders) {
|
||||
css(importLoaders) {
|
||||
// css-loader
|
||||
// https://github.com/webpack-contrib/css-loader
|
||||
const cssLoaderAlias = {
|
||||
@ -69,52 +69,42 @@ export default class StyleLoader {
|
||||
[`/${this.staticDir}`]: path.join(this.srcDir, this.staticDir)
|
||||
}
|
||||
|
||||
loaders.unshift({
|
||||
return {
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: this.sourceMap,
|
||||
minimize: !this.dev,
|
||||
importLoaders: loaders.length, // Important!
|
||||
importLoaders: importLoaders,
|
||||
alias: cssLoaderAlias
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
extract(loaders) {
|
||||
if (this.extractCSS) {
|
||||
loaders.unshift(MiniCssExtractPlugin.loader)
|
||||
if (this.dev) {
|
||||
// css-hot-loader
|
||||
// https://github.com/shepherdwind/css-hot-loader
|
||||
loaders.unshift({
|
||||
loader: 'css-hot-loader',
|
||||
options: { sourceMap: this.sourceMap }
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
vueStyle(loaders) {
|
||||
extract() {
|
||||
if (this.extractCSS) {
|
||||
return MiniCssExtractPlugin.loader
|
||||
}
|
||||
}
|
||||
|
||||
vueStyle() {
|
||||
// https://github.com/vuejs/vue-style-loader
|
||||
loaders.unshift({
|
||||
return {
|
||||
loader: 'vue-style-loader',
|
||||
options: { sourceMap: this.sourceMap }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
apply(ext, loaders = []) {
|
||||
// Normalize loaders
|
||||
loaders = this.normalize(loaders)
|
||||
const _customLoaders = [].concat(
|
||||
this.postcss(loaders),
|
||||
this.styleResource(ext),
|
||||
this.normalize(loaders)
|
||||
).filter(Boolean)
|
||||
|
||||
// -- Configure additional loaders --
|
||||
this.styleResource(ext, loaders)
|
||||
this.postcss(loaders)
|
||||
this.css(loaders)
|
||||
if (!this.extract(loaders)) {
|
||||
this.vueStyle(loaders)
|
||||
}
|
||||
|
||||
return loaders
|
||||
return [].concat(
|
||||
this.extract() || this.vueStyle(),
|
||||
this.css(_customLoaders.length),
|
||||
_customLoaders
|
||||
).filter(Boolean)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user