如何使用 Webpacker 将 `includePaths` 添加到 Sass 加载器
How to add `includePaths` to Sass loader with Webpacker
我覆盖了 sass-loader 配置以包含 node_modules 路径:
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
environment.loaders.prepend('sass', {
test: /\.(css|scss|sass)$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}, {
loader: 'sass-loader',
options: {
includePaths: ['node_modules'],
}
}]
})
module.exports = environment
Webpack 编译没有错误,但是它不再输出 application.css 包。
我进行了更改,因为我从我的 Sass 文件导入的 NPM 插件从其他插件导入的代码在编译时导致错误。
找到解决方案:
environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.includePaths = ['node_modules']
参考:https://github.com/rails/webpacker/blob/3-x-stable/docs/webpack.md
我覆盖了 sass-loader 配置以包含 node_modules 路径:
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
environment.loaders.prepend('sass', {
test: /\.(css|scss|sass)$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}, {
loader: 'sass-loader',
options: {
includePaths: ['node_modules'],
}
}]
})
module.exports = environment
Webpack 编译没有错误,但是它不再输出 application.css 包。
我进行了更改,因为我从我的 Sass 文件导入的 NPM 插件从其他插件导入的代码在编译时导致错误。
找到解决方案:
environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.includePaths = ['node_modules']
参考:https://github.com/rails/webpacker/blob/3-x-stable/docs/webpack.md