【问题标题】:Pug + webpack-dev-server哈巴狗 + webpack-dev-server
【发布时间】:2018-10-20 22:37:43
【问题描述】:

我正在使用 webpack v4,我正在尝试将 Pugwebpack-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
    })
  ]
};

【问题讨论】:

  • 你得到答案了吗?我似乎有同样的问题,并且有类似的配置。

标签: javascript webpack frontend pug-loader


【解决方案1】:

您好,您必须在 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'
    })
  ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多