npm i
npm run build -- --entry ./index.js
HTML emitted with <div class="<some css module hashed classname>"> and css chunk that inserted to html head.
HTML emmited with <div class=""> and no css chunk at all.
| <div class="<%= require('./item.css').item %>"></div> |
| // Just to make sure webpack is build something |
| .item { | |
| color: red; | |
| } |
| { | |
| "private": true, | |
| "name": "example", | |
| "scripts": { | |
| "build": "webpack" | |
| }, | |
| "devDependencies": { | |
| "css-loader": "^5.0.0", | |
| "html-webpack-plugin": "^5.0.0-alpha.10", | |
| "mini-css-extract-plugin": "^1.2.1", | |
| "webpack": "^5.4.0", | |
| "webpack-cli": "^4.1.0" | |
| } | |
| } |
| const HTMLWebpackPlugin = require('html-webpack-plugin'); | |
| const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
| module.exports = { | |
| mode: 'development', | |
| devtool: false, | |
| module: { | |
| rules: [ | |
| { | |
| test: /\.css$/, | |
| use: [ | |
| { | |
| loader: MiniCssExtractPlugin.loader | |
| }, | |
| { | |
| loader: 'css-loader', | |
| options: { | |
| modules: true | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| plugins: [ | |
| new HTMLWebpackPlugin({ | |
| template: 'index.ejs' | |
| }), | |
| new MiniCssExtractPlugin(), | |
| ] | |
| }; |
@klesun nope, with
modules: trueit returns JSON with hashed classes of CSS file.