7

我正在使用 webpack v4 并且我正在尝试使用Pugwithwebpack-dev-server但是当我运行webpack-dev-server --mode development它时不提供已编译Pug的 . 请帮忙。我不知道该怎么办。谢谢您的回复。这是我的配置:

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

module.exports = {
  entry: './src/js/main.js',
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.pug$/,
        use: {
          loader: 'pug-loader',
          options: {
            pretty: true
          }
        }
      }
    ]
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    hot: true,
    open: true,
    progress: true
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.join(__dirname, 'src/templates/pages/index.pug'),
      inject: false
    })
  ]
};

4

1 回答 1

0

您好,您必须在 HtmlWebpackPlugin 上指定文件名,以便您可以从 localhost:3000 或 localhost:3000/index.html 提供您的 html

devServer: {
     ...,
     port: 3000
}
...
plugins: [
    new HtmlWebpackPlugin({
      template: path.join(__dirname, 'src/templates/pages/index.pug'),
      filename: 'index.html'
    })
  ]
于 2019-03-20T08:46:02.750 回答