webpack - 如何使用带有 webpack、sass-loader 和 dart sass 的波浪号前缀导入 sass
问题描述
这是我的仓库 https://github.com/inspiraller/eg-webpack4-dartsass-import
我可以删除波浪号,它会起作用,但是我正在转换一个包含大量现有~node_modules的大型 repo, 所以只想更新 webpack 以支持现有的波浪号来引用根。
快速参考 - 这些是我已经尝试过但不起作用的 webpack sass-loader 规则:
{
loader: 'sass-loader',
options: {
sourceMap: isDevelopment,
// https://www.npmjs.com/package/sass-loader
// Prefer `dart-sass`
implementation: sass,
sassOptions: {
fiber: false, // not compatibile with node 16+
},
sassOptions: (loaderContext) => {
console.log('loaderCointext = ', loaderContext) // not even printing any output (suspect because error is breaking)
},
includePaths: ["~"], // tried this doesn't work
webpackImporter: true // just in case - tilde won't work ? - https://webpack.js.org/loaders/sass-loader/ webpackImporter
}
}
解决方案
好的,我想我已经用这个解决方案修复了错误:
module.exports = {
resolve: {
// need * for scss...
extensions: ['*', '.jsx', '.js'],
alias: { // fix broken sass
'~node_modules': path.resolve(__dirname, 'node_modules')
}
}
//, other stuff ...
}
但我不确定是否应用了 css,因为它没有在 sassOptions 回调方法中被拾取:
sassOptions: loaderContext => {
const {resourcePath} = loaderContext
if (resourcePath.indexOf('node_modules') !== -1) {
console.log({resourcePath})
}
推荐阅读
- powershell - 分组事件日志条目和计数错误
- mongodb - mongodb failed to start on ubuntu 18.04lts
- java - 如何在 JSP 中迭代 JSON 响应?
- gradle - 为什么我无法使用 Gradle Kotlin DSL (5.0) 访问 build.gradle.kts 的“插件”部分中的项目属性?
- javascript - 谷歌地图全景街景放大和缩小但没有可用的事件
- python - Create a widget to embed into QMainWindow
- javascript - Firebase Function always finished with timeout
- curl - 如何让 cURL 不显示进度条但仍提供统计信息?
- r - RLANG - SAS 中带有 R 脚本的图形消失
- r - 不使用 RStudio 从 R 启动文件 rmd ( markdown )