Skip to content

Instantly share code, notes, and snippets.

@SrShark
Last active April 27, 2020 13:55
Show Gist options
  • Save SrShark/7262b166343c4dc8099dad868652f298 to your computer and use it in GitHub Desktop.
Save SrShark/7262b166343c4dc8099dad868652f298 to your computer and use it in GitHub Desktop.
Webpack-dev-server - Module Replacement (HMR) don't reload PUG files changes

You need install raw-loader

Webpack 3 Config

  module: {
    rules: [
      {
        test: /\.pug$/,
        use: [
          {loader: 'raw-loader'},
          {loader: 'pug-html-loader'}
        ]
      }
    ]
  },
  plugins: [
    // Templates HTML
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: './src/templates/index.pug'
    }),
    new HtmlWebpackPlugin({
      filename: 'contact.html',
      template: './src/templates/contact.pug'
    }),
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin()
  ]

app.js

// import all template pug

import 'raw-loader!./templates/index.pug'
import 'raw-loader!./templates/contact.pug'

That makes webpack listen the changes in the pug files, but it also adds this js code to the bundle.js, then you need to process app.js to clean the bundle.js.

@SrShark
Copy link
Author

SrShark commented Dec 1, 2017

@infantito why doesn't work? let me see your config.

Remember process your file.pug with raw-loader!./file.pug. Set this configuration in your entry point.

Use relative path to your files!

@long-hp
Copy link

long-hp commented Jan 25, 2018

[HELP]
Refesh browser when I save changes to pug file @@
https://drive.google.com/file/d/1q1jT4U26G4IXSdqmOsCy-yYElEz0VAO_/view
After:
https://drive.google.com/file/d/1bf75LDtEGnJ8UW01LEj1e_EMahetc0Zq/view
[HMR] Waiting for update signal from WDS...
[WDS] Hot Module Replacement enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment