首页 文章

Webpack 3,Extract Text插件不解析sass-loader includePaths

提问于
浏览
1

我使用以下设置处理旧项目:

webpack@3.0.0
extract-text-webpack-plugin@2.1.2

我现在正在尝试一个新项目,所以升级到:

webpack@3.8.1
extract-text-webpack-plugin@3.0.1.

Webpack配置完全相同,但现在我遇到了错误 .

我正在使用node-bourbon,我想让它在所有条目中都可用,而不是每次都要导入它 .

我有一个SCSS文件:stylesheets / tools / mixins / bourbon.scss(应该)只是导入波本威士忌: @import 'bourbon';

然后我使用sass-resources-loader使所有模块(以及其他一些mixins)可用于所有模块(参见下面的配置) .

webpack配置: { test: /\.scss$/, use: ExtractTextPlugin.extract({ use: [ ... { loader: "sass-loader", options: { sourceMap: true, includePaths: require('bourbon').includePaths } }, { loader: 'sass-resources-loader', options: { resources: [ './frontend/stylesheets/settings/*.scss', './frontend/stylesheets/tools/**/*.scss' ] }, }, ] }) },

但是,SCSS文件中的import语句未解析为node_modules,它会尝试引用自身,因此我收到此错误: Module build failed: @import 'bourbon'; ^ An @import loop has been found:

看来node-bourbon的includePaths被忽略了吗?

更新:

我已经设法通过直接引用波旁语来解决这个问题: @import '~bourbon/app/assets/stylesheets/_bourbon';

不理想,但它做的工作 .

有趣的是,当我将bourbon @import 'bourbon'; 包含在一个文件中时,它不会将sass-loader中的includePaths传递给sass-resource-loader中引用的模块 .

1 回答

  • 1

    我不是肯定的,但我相信 includepaths 必须是一个数组,即使只有一个条目 .

    另外bourbonbourbon-neat是官方的傀儡,所以你可能会有更好的运气而不是 node-bourbon .

    编辑澄清:

    您需要为选项→输入以下内容

    options: {
                  sourceMap: true,
                  includePaths: [require('bourbon').includePaths]
                }
    

相关问题