3

一个简单的 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';

~

4

1 回答 1

3

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

于 2018-07-11T20:48:57.723 回答