The webpack version of this tutorial: 4.46.0
Our webpack.config.js configuration is as follows:
const path = require('path')
//module.exports是commonjs语法
module.exports = {
entry: './src/index.js',
output: {
filename: 'built.js',
path: path.join(__dirname, 'build')
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
plugins: [],
mode: 'development'
}
Introduce a less file, if there is no configuration, an webpack -c .\webpack.config.js
error will be reported when executed :
We need to configure less-loader
:
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
}
Then install less-loader
andless
npm i less-loader less -D
success!