Working with SASS in Webpack
Let's now learn how to work with the SASS preprocessor. To do this, we first need to install SASS itself:
npm install sass --save-dev
Then the corresponding loader:
npm install sass-loader --save-dev
Now let's import several SASS files to the entry point:
import './styles1.sass';
import './styles2.sass';
Let's configure Webpack to transform SASS code into CSS:
export default {
entry: './src/index.js',
rules: [
{
test: /\.sass/i,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
],
};
Now let's configure Webpack so that the transformed CSS is collected into one common bundle:
export default {
entry: './src/index.js',
plugins: [new MiniCssExtractPlugin()],
module: {
rules: [
{
test: /\.sass/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
};
Include several SASS files in your entry point. Compile them into CSS.