sass-loader: webpack alias with tilde not working for imports
With sass-loader < 7.0.0 this worked fine
// webpack config
resolve: {
alias: {
fonts: path.resolve(__dirname, '../src/assets/fonts'),
settings: path.resolve(__dirname, '../src/assets/sass/settings.scss'),
},
},
// works
@import '~settings';
// works
@font-face {
font-family: 'Rubik';
font-style: normal;
font-weight: 300;
src: url('~fonts/rubik-v7-latin-300.woff2') format('woff2'),
url('~fonts/rubik-v7-latin-300.woff') format('woff');
}
With sass-loader >= 7.0.0
// error: can't resolve '~settings'
@import '~settings';
// works
@font-face {
font-family: 'Rubik';
font-style: normal;
font-weight: 300;
src: url('~fonts/rubik-v7-latin-300.woff2') format('woff2'),
url('~fonts/rubik-v7-latin-300.woff') format('woff');
}
Is this an expected behavior or an bug?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 22
- Comments: 32 (12 by maintainers)
Commits related to this issue
- fix: Bare imports not working sometimes Fixes #566 Supersedes https://github.com/webpack-contrib/sass-loader/pull/577 — committed to webpack-contrib/sass-loader by jhnns 6 years ago
- fix: Bare imports not working sometimes Fixes #566 Supersedes https://github.com/webpack-contrib/sass-loader/pull/577 — committed to webpack-contrib/sass-loader by jhnns 6 years ago
- fix: Bare imports not working sometimes (#579) Fixes #566 Supersedes https://github.com/webpack-contrib/sass-loader/pull/577 — committed to webpack-contrib/sass-loader by jhnns 6 years ago
I still have problems with ~ syntax.
I have
Static
alias in webpack and scss file with content below.Chrome console
Webpack config style rules:
I tried
sass-loader@6
andsass_loader@7.0.3
.Any suggestions? Maybe I did something wrong?
Hi was this resolved? I am having the same problem using the tilde. eg. @import β~SharedStyles/cardβ;
However, my configuration currently works for aliases with .jsx and .js
On
sass-loader
version < 7 you need to explicitely set thewebpackImporter
option totrue
:Hi, π looks like it also not work when resolve.alias property starts with tilde character. e.g
would the alias start with
~
is not allow ?Found problem, https://github.com/webpack-contrib/sass-loader/blob/master/lib/importsToResolve.js#L6 use
g
what changelastIndex
after each search.Try:
in webpack config
Link to Repo: https://github.com/philippkuehn/sass-loader-alias-bug
After some testing I found out that this error only occurs in combination with Vue. Iβm not sure if this error is related to sass-loader or vue-loader but everything worked fine with sass-loader v6.
I will try, but not these days. Too busy π
Write tests is hard, a spend 1 hours on issue and spend 4 hours on tests, but did not make it