Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to inject NODE_ENV param into sass file using Webpack & sass loader?

I'm trying to inject NODE_ENV into a sass file, so I can have different output for dev/prod env, and have a sass function that has a condition like that inside it: @if (NODE_ENV == 'prod') {}

my webpack.config looks like this:

module: {
    loaders: [{
        test: /\.scss$/,
        loader: "style-loader!raw-loader!sass-loader?includePaths[]=" + path.resolve(__dirname, "./node_modules/compass-mixins/lib")
    }]
}

I tried passing a data parameter to the loader, but nothing that I tried worked. will appreciate any help!

like image 575
Dima Feldman Avatar asked Mar 02 '16 14:03

Dima Feldman


1 Answers

this is the code directly from sass-loader repo.

webpack.config.js

... sassLoader: { data: "$env: " + process.env.NODE_ENV + ";" } ...

like image 108
Luca Colonnello Avatar answered Sep 22 '22 20:09

Luca Colonnello