Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add `includePaths` to Sass loader with Webpacker

I overrode the sass-loader configuration to include the node_modules path:

// 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 compiles without errors, however it does not output an application.css pack anymore.

I made the change, because NPM plugins I imported from my Sass files who imported code from other plugins were causing errors when compiling.

like image 329
heroxav Avatar asked Feb 05 '18 16:02

heroxav


People also ask

Is Sass-loader deprecated?

Warning: LibSass and Node Sass are deprecated. While they will continue to receive maintenance releases indefinitely, there are no plans to add additional features or compatibility with any new CSS or Sass features. Projects that still use it should move onto Dart Sass.

Does Sass-loader require node Sass?

sass-loader requires you to install either Dart Sass, Node Sass on your own (more documentation can be found below) or Sass Embedded. This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.


1 Answers

Found the solution:

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

Reference: https://github.com/rails/webpacker/blob/3-x-stable/docs/webpack.md

like image 172
heroxav Avatar answered Sep 24 '22 01:09

heroxav