⊗tlWpCsLC 37 of 55 menu

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:

npm install less --save-dev

Then the corresponding loader:

npm install less-loader --save-dev

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

import './styles1.less'; import './styles2.less';

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

export 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:

export default { entry: './src/index.js', plugins: [new MiniCssExtractPlugin()], module: { rules: [ { test: /\.less$/i, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'less-loader', ], }, ], }, };

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

uzchiitptnl