
[英]What is the difference between using extract-text-webpack-plugin and linking a merged CSS file in an HTML header?
[英]CSS file won't rebuild after commenting out file when using extract-text-webpack-plugin
导入JavaScript文件时,我试图将CSS提取到其自己的文件中。 最初的构建工作正常,但是当我观看文件时,我注释了导入css的行( import './test.css';
),webpack只重建JS文件和CSS文件( main.css
)未更新(它将样式保留在样式表中)。
当我注释掉css导入时,如何获取要重建的css文件?
webpack.config.js
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'static'),
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin('main.css')
],
};
index.js
// If I comment out the following import while the watch is running,
// it will not remove the CSS from main.css
import './test.css';
document.body.innerText = 'Hello';
test.css
body {
background: lightcoral;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.