7

I'm using webpack v4 and I'm trying to use Pug with webpack-dev-server but when I run webpack-dev-server --mode development it doesn't serve compiled Pug. Please, help. I don't know what to do. Thanks for reply. Here is my config:

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
    })
  ]
};

1
  • 2
    Did you get an answer? I seem to have the same problem, and have a similar config.
    – MattG
    Oct 18, 2018 at 22:41

1 Answer 1

0

Hello you have to specify the filename on HtmlWebpackPlugin so you can have your html served from localhost:3000 or localhost:3000/index.html

devServer: {
     ...,
     port: 3000
}
...
plugins: [
    new HtmlWebpackPlugin({
      template: path.join(__dirname, 'src/templates/pages/index.pug'),
      filename: 'index.html'
    })
  ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.