V
V
Vanya Huk2018-08-01 23:43:56
Laravel
Vanya Huk, 2018-08-01 23:43:56

How to set up laravel-mix and react-hot-loader properly?

How to set up laravel-mix and react-hot-loader properly?
here is webpack.mix

let mix = require('laravel-mix')

mix.react('resources/assets/js/app.js', 'public/js');
//.sass('resources/assets/sass/app.scss', 'public/css');



mix.webpackConfig({

  output: {
    publicPath: "http://localhost:8080/"
  },

    devServer: {
      hot: true, // this enables hot reload
      inline: true, // use inline method for hmr
      contentBase: path.join(__dirname, "public"),
      https: false, //true
      port: 8080,
      headers: {"Access-Control-Allow-Origin": "*"},
      watchOptions: {
        exclude: [/bower_components/, /node_modules/]
      },
    },

      node: {
        fs: "empty",
        module: "empty"
      },


});


Mix.listen("configReady", webpackConfig => {

  if (Mix.isUsing("hmr")) {

    webpackConfig.entry = Object.keys(webpackConfig.entry).reduce(
      (entries, entry) => {
        entries[entry.replace(/^\//, "")] = webpackConfig.entry[entry];

        console.log(entries);
        return entries;
      },
      {}
    );

    webpackConfig.plugins.forEach(plugin => {
      if (plugin.constructor.name === "ExtractTextPlugin") {
        console.log(plugin.filename);
        plugin.filename = plugin.filename.replace(/^\//, "");
        console.log(plugin.filename);
      }
    });
  }
});

but for some reason it does not work, although there are no errors
5b621bf06dc8f484563875.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question