Working with LESS in Webpack

Let's now learn how to work with the LESS preprocessor. To do this, we first need to install LESS itself:

terminalnpm install less --save-dev

Then the corresponding loader:

terminalnpm install less-loader --save-dev

Now let's import several LESS files to the entry point:

src/index.jsimport './styles1.less';
import './styles2.less';

Let's configure Webpack to transform LESS code into CSS:

webpack.config.jsexport default {
  entry: './src/index.js',
  rules: [
    {
      test: /\.less$/i,
      use: [
        'style-loader',
        'css-loader',
        'less-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: /\.less$/i,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'less-loader',
        ],
      },
    ],
  },
  
};
Задание 1

Include some LESS files in your entry point. Compile them into CSS.