如何强制 webpack 将纯 CSS 代码放入 HTML head 的 style 标签中? [英] How to force webpack to put the plain CSS code into HTML head's style tag?
本文介绍了如何强制 webpack 将纯 CSS 代码放入 HTML head 的 style 标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个webpack.config
:
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineStylePlugin = require('html-webpack-inline-style-plugin');
const path = require('path');
module.exports = {
mode: 'production',
entry: {
main: [
'./src/scss/main.scss'
]
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '',
filename: 'js/[name].js'
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true
})
]
},
module: {
rules: [
{
test: /\.scss$/,
use: [
'css-loader',
'sass-loader',
]
},
// ... other stuffs for images
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/main.html',
filename: 'main.html'
}),
new HtmlWebpackInlineStylePlugin()
]
};
我尝试过这种配置,但效果不佳,因为 CSS 代码已生成到 main.css 文件中.
I tried this configuration, but this isn't working well, because the CSS code is generated into the main.css file.
但是如果我将 CSS 代码作为