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:
terminalnpm install sass --save-dev
Then the corresponding loader:
terminalnpm install sass-loader --save-dev
Now let's import several SASS files to the entry point:
src/index.jsimport './styles1.sass';
import './styles2.sass';
Let's configure Webpack to transform SASS code into CSS:
webpack.config.jsexport 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:
webpack.config.jsexport default {
entry: './src/index.js',
plugins: [new MiniCssExtractPlugin()],
module: {
rules: [
{
test: /\.sass/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
};
Задание 1
Include several SASS files in your entry point. Compile them into CSS.