-
Notifications
You must be signed in to change notification settings - Fork 918
Webpack 5 compatibility: Options from some rules are applied to others #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
{
test: /\.css$/,
use: () => [{
loader: 'css-loader',
options: {
url: true
}
}]
}
// or
{
test: /\.css$/,
use: [{
loader: 'css-loader',
options: {
url: true
},
ident: 'css-loader-ident'
}]
} |
Related issue, this kind of configuration does not work anymore in webpack 5. The CSS loader for CSS module grabs the configuration from non-CSS-module CSS loader. // EDIT: code removed, see fixed configuration below EDIT: Fixed by adding Gonna paste this for people who need updated CSS loader configuration for Vue loader. const vueStyleLoader: webpack.RuleSetLoader = {
loader: LoaderPaths.vueStyle,
ident: 'vue-style-loader'
};
// https://vue-loader.vuejs.org/guide/css-modules.html#usage
const cssModulesLoader: webpack.RuleSetLoader = {
loader: LoaderPaths.css,
ident: 'vue-css-module-loader',
options: {
// enable CSS Modules
modules: {
localIdentName: '[local]_[contenthash:8]'
},
url: false
}
};
const cssLoader: webpack.RuleSetLoader = {
loader: LoaderPaths.css,
ident: 'vue-css-loader',
options: {
url: false
}
};
return {
test: /\.css$/,
resourceQuery: /\?vue/,
oneOf: [
{
// this matches <style module>
// ./HelloWorld.vue?vue&type=style&index=0&module=true&lang=css&
resourceQuery: /module=true/,
use: [vueStyleLoader, cssModulesLoader]
},
{
// this matches plain <style> or <style scoped>
// HelloWorld.vue?vue&type=style&index=0&lang=css&
use: [vueStyleLoader, cssLoader]
}
]
}; |
Version
15.8.3
Reproduction link
https://github.com/Lyrkan/repro-vue-loader-webpack5
Steps to reproduce
vue-loader
and Webpack 5 with the three following rules :{ test: /\.js$/, use: [ { loader: 'babel-loader', options: {} } ] }
{ test: /\.css$/, use: [ { loader: 'css-loader', options: { url: true } } ] }
(url
can be replaced by any option that exists incss-loader
but not inbabel-loader
){ test: /\.vue$/, loader: 'vue-loader' }
Import a
.vue
file that contains a<script>
tagTry to compile the project
What is expected?
Should compile fine
What is actually happening?
The build fails because the
url
option meant for thecss-loader
is passed to thebabel-loader
:It does not happen when using Webpack 4
It does not happen either when not using
Rule.use
or whenoptions
is not specified in thebabel-loader
rule.The text was updated successfully, but these errors were encountered: