sagold / handlebars-webpack-plugin

Renders your html-template at build time
161 stars 45 forks source link

Uncaught Error: [HMR] Hot Module Replacement is disabled. #24

Closed micahblu closed 6 years ago

micahblu commented 6 years ago

The plugin works for me but unfortunately at the expense of hot module replacement. I have three plugins, it is only when I remove handlebars-webpack-plugin that hot module replacement works. It appears to be the only factor effecting it.

my webpack.dev.js:

const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const HandlebarsPlugin = require("handlebars-webpack-plugin");

module.exports = merge(common, {
  devtool: 'eval',
  output: {
    filename: 'app.js',
    publicPath: './src',
    path: path.resolve(__dirname, 'src')
  },
  devServer: {
    hot: true,
    // activate hot reloading

    contentBase: path.resolve(__dirname, 'src'),
    // match the output path

    publicPath: '/'
    // match the output `publicPath`
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new HandlebarsPlugin({
      // path to hbs entry file(s)
      entry: path.join(process.cwd(), "src", "index.hbs"),
      // output path and filename(s)
      // if ommited, the input filepath stripped of its extension will be used
      output: path.join(process.cwd(), "src", "[name].html"),
      // data passed to main hbs template: `main-template(data)`
      //data: require("./src/index.json"),
      // or add it as filepath to rebuild data on change using webpack-dev-server
      data: path.join(__dirname, "src/index.json")
    })
  ]
});

webpack.common.js

var path = require('path');
var WebpackNotifierPlugin = require('webpack-notifier');

module.exports = {
  entry: [
    'react-hot-loader/patch',
    'webpack-dev-server/client?http://localhost:8080',
    'webpack/hot/only-dev-server',
    path.resolve(__dirname, 'src/index.tsx')
  ],
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
    modules: [path.resolve(__dirname, "src"), "node_modules"]
  },

  module: {
    rules: [
      { test: /\.(tsx|ts|jsx)$/, loaders: ['babel-loader', 'ts-loader'] },
      { 
        test: [/\.css$/, /\.scss$/],
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' },
          { loader: 'sass-loader'}
        ]
      },
      {
        test: /\.(png|jpg|gif|svg|eot|otf|ttf|woff|woff2)$/,
        loader: 'url-loader',
        options: {
          limit: 100000
        }
      }
    ]
  },
  plugins: [
    new WebpackNotifierPlugin({ alwaysNotify: true }),
  ]
};
micahblu commented 6 years ago

Update this error is now happening independently of handlebars-webpack-plugin.

sagold commented 6 years ago

Hi micah.

Thank you for taking your time and closing this issue. Good luck in finding the problem.

Regards, sagold