By default, webpack will include your every CSS files (from libs and generated) in a <style>
tag in the index.html
file.
You need some plugins to generate the CSS from your LESS file and extract CSS files as separate files:
Here is an extract of my webpack configuration file for the LESS/CSS part. I'm working with some CSS files from librairies which are concatenated in a libs.css
and a main LESS file (which includes 20+ other LESS files) which is compiled in a style.css
file.
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('libs.css');
var extractLESS = new ExtractTextPlugin('style.css');
module.exports = {
...
module: {
...
loaders: [{
// load css without sourcemap
test: /\.css$/,
loader: extractCSS.extract(
'css'
)
}, {
// compile less with source maps
test: /\.less$/,
loader: extractLESS.extract(
'css?sourceMap!less?sourceMap'
)
}]
},
plugins: [
// extract inline css into separate files with sourcemaps
extractCSS,
extractLESS
],
resolve: {
alias: {
...
'less': path.join(__dirname, 'src/less'),
'css': path.join(__dirname, 'src/css'),
}
}
};