【发布时间】:2018-08-29 22:32:27
【问题描述】:
我的项目结构:
webpack.config.js
app--
--> src
---->> components
------>>> myComponent.js
------>>> myComponent.scss
--> styles
---->> variables.scss
在 webpack.config module.exports 中:
...
resolve: {
alias: {
styles: path.join(__dirname, 'app/styles')
}
}
在我的文件中 - myComponent.scss:
@import "styles/variables";
我在构建 bundle.js 时遇到此错误:
Module build failed:
@import "styles/variables";
^
File to import not found or unreadable: styles/variables
如何在 sass 文件中 @import 别名?
【问题讨论】:
-
也许添加有关项目目录结构的信息,尤其是提到的文件,会有所帮助。
-
为问题添加了项目结构
-
一个非常快速的观察 - 可能无关紧要:目录
styles包含在alias.styles中作为path.join(..., 'app/styles')和在导入中作为@import "styles/variables"。可能需要@import "variables"。 -
@NikosParaskevopoulos 这就是在 webpack 中定义和使用别名的方式 - webpack.github.io/docs/configuration.html#resolve-alias
-
您找到解决方案了吗?
标签: sass webpack autoprefixer sass-loader