Pug + webpack-dev-server
Asked Answered
A

1

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
    })
  ]
};
Aldus answered 10/5, 2018 at 15:38 Comment(1)
Did you get an answer? I seem to have the same problem, and have a similar config.Was
V
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'
    })
  ]
Vick answered 20/3, 2019 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.