gpt4 book ai didi

css - webpack HMR 没有加载 css

转载 作者:行者123 更新时间:2023-11-28 09:55:36 26 4
gpt4 key购买 nike

一个简单的 webpack 配置但不起作用:

var path = require("path");
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
module: {
rules: [
{
test:/\.css$/,
use:['style-loader','css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html',
title: 'My Awesome application',
myPageHeader: 'Hello World',
template: './src/index.html',
})
],
devServer: {
port: 8000,
hot: true
},

};

当我使用“hot: false”运行时它工作,我的 CSS 被加载,但是使用“hot: true”我可以看到我的 html 但样式没有加载...

"webpack": "^4.16.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"

如果我使用 webpack 构建,然后在我的浏览器中打开 dist/index.html,它也可以工作。

在 index.js 中,我像这样导入了我的 css:

import './styles/app.css';

~

最佳答案

我删除了 hot: true 并在我的脚本中添加了 --hot 选项,命令行版本自动添加了一个插件。

关于css - webpack HMR 没有加载 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51289135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com