-
-
Notifications
You must be signed in to change notification settings - Fork 385
Module-level aliases don't work #1122
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
That's expected, because you set it not for SASS, you set it for JS (under the hood webpack convert CSS into JS) Please use on global level: // ...
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
runtime: false,
}),
],
resolve: {
byDependency: {
"sass": {
extensions: ['.scss'],
alias: {
'@aliased': path.resolve(__dirname, 'sass', 'alias'),
},
}
}
},
module: {
rules: [
// ... |
Just comment:
and use on a module level: {
test: /\.scss$/,
exclude: /node_modules/,
resolve: {
byDependency: {
"sass": {
extensions: ['.scss'],
alias: {
'@aliased': path.resolve(__dirname, 'sass', 'alias'),
},
}
}
},
use: [
/*{
loader: MiniCssExtractPlugin.loader,
},*/
{
loader: 'css-loader',
options: {
sourceMap: true,
url: false,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
sassOptions: {
silenceDeprecations: ['import'],
},
},
},
],
}, And it will work, the main problem here is what this code applied to JS (mini-css-extract-plugin doing it in Also any module can contain different resolve logic, for example you can have mixed |
So I want to say it is resolve: {
extensions: ['.scss'],
alias: {
'@aliased': path.resolve(__dirname, 'sass', 'alias'),
},
}, So no problems with |
Bug report
Actual Behavior
Although this loader does support
resolve.alias
at the top level of the Webpack config, it seems module-specific aliases are ignored (module.rules[i].resolve.alias
). This results inCan't find stylesheet to import
errors, which occurs for both@use
and@import
. One reason for module-level aliases is so that every rule can have its own aliases, without any risk of accidentally importing SASS into TypeScript for example (or vice versa even).This error seems to originate from
sass-loader
if I'm interpreting this correctly, which is why I created the issue here and not elsewhere.Expected Behavior
Perhaps there is a way to just ask Webpack what aliases are relevant for the current loader/rule? That way it will keep working even if they ever add aliases at more levels.
How Do We Reproduce?
npm i
of coursenpm run build-fail
ornpm run build-good
I only used
@import
in this example because it's closer to my actual scenario (can't use@use
due to dependencies), and I figured it's pretty redundant to show@use
since the behaviour is exactly the same anyway.Please paste the results of
npx webpack-cli info
here, and mention other relevant informationThe text was updated successfully, but these errors were encountered: