mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +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]
|
const extResource = this.resources[ext]
|
||||||
// style-resources-loader
|
// style-resources-loader
|
||||||
// https://github.com/yenshih/style-resources-loader
|
// https://github.com/yenshih/style-resources-loader
|
||||||
@ -37,31 +37,31 @@ export default class StyleLoader {
|
|||||||
? extResource
|
? extResource
|
||||||
: [extResource]
|
: [extResource]
|
||||||
|
|
||||||
loaders.push({
|
return {
|
||||||
loader: 'style-resources-loader',
|
loader: 'style-resources-loader',
|
||||||
options: Object.assign(
|
options: Object.assign(
|
||||||
{ patterns },
|
{ patterns },
|
||||||
this.resources.options || {}
|
this.resources.options || {}
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postcss(loaders) {
|
postcss() {
|
||||||
// postcss-loader
|
// postcss-loader
|
||||||
// https://github.com/postcss/postcss-loader
|
// https://github.com/postcss/postcss-loader
|
||||||
if (this.postcssConfig) {
|
if (this.postcssConfig) {
|
||||||
const config = this.postcssConfig.config()
|
const config = this.postcssConfig.config()
|
||||||
if (config) {
|
if (config) {
|
||||||
loaders.unshift({
|
return {
|
||||||
loader: 'postcss-loader',
|
loader: 'postcss-loader',
|
||||||
options: Object.assign({ sourceMap: this.sourceMap }, config)
|
options: Object.assign({ sourceMap: this.sourceMap }, config)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
css(loaders) {
|
css(importLoaders) {
|
||||||
// css-loader
|
// css-loader
|
||||||
// https://github.com/webpack-contrib/css-loader
|
// https://github.com/webpack-contrib/css-loader
|
||||||
const cssLoaderAlias = {
|
const cssLoaderAlias = {
|
||||||
@ -69,52 +69,42 @@ export default class StyleLoader {
|
|||||||
[`/${this.staticDir}`]: path.join(this.srcDir, this.staticDir)
|
[`/${this.staticDir}`]: path.join(this.srcDir, this.staticDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
loaders.unshift({
|
return {
|
||||||
loader: 'css-loader',
|
loader: 'css-loader',
|
||||||
options: {
|
options: {
|
||||||
sourceMap: this.sourceMap,
|
sourceMap: this.sourceMap,
|
||||||
minimize: !this.dev,
|
minimize: !this.dev,
|
||||||
importLoaders: loaders.length, // Important!
|
importLoaders: importLoaders,
|
||||||
alias: cssLoaderAlias
|
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
|
// https://github.com/vuejs/vue-style-loader
|
||||||
loaders.unshift({
|
return {
|
||||||
loader: 'vue-style-loader',
|
loader: 'vue-style-loader',
|
||||||
options: { sourceMap: this.sourceMap }
|
options: { sourceMap: this.sourceMap }
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(ext, loaders = []) {
|
apply(ext, loaders = []) {
|
||||||
// Normalize loaders
|
const _customLoaders = [].concat(
|
||||||
loaders = this.normalize(loaders)
|
this.postcss(loaders),
|
||||||
|
this.styleResource(ext),
|
||||||
|
this.normalize(loaders)
|
||||||
|
).filter(Boolean)
|
||||||
|
|
||||||
// -- Configure additional loaders --
|
return [].concat(
|
||||||
this.styleResource(ext, loaders)
|
this.extract() || this.vueStyle(),
|
||||||
this.postcss(loaders)
|
this.css(_customLoaders.length),
|
||||||
this.css(loaders)
|
_customLoaders
|
||||||
if (!this.extract(loaders)) {
|
).filter(Boolean)
|
||||||
this.vueStyle(loaders)
|
|
||||||
}
|
|
||||||
|
|
||||||
return loaders
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user