如何使用Webpacker将“includePaths”添加到Sass加载器中

时间:2018-02-05 16:08:29

标签: ruby-on-rails webpack sass sass-loader 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插件从其他插件导入代码时导致编译错误。

1 个答案:

答案 0 :(得分:4)

找到解决方案:

environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.includePaths = ['node_modules']