electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
905 stars 171 forks source link

Adding files to the list of files that are watched by webpack #178

Open patsimm opened 6 years ago

patsimm commented 6 years ago

Hello,

we are having a lerna project and one of our modules is being built by electron-webpack. For that module all HMR stuff in renderer and main process works perfect. Now it would be nice to be able to configure webpack so if we change a file in our other modules the renderer still gets rebuilt when running in watch mode.

For that I already modified the webpack configuration for our electron module so it wouldn't load the other built modules but build all our modules from it's sources. That works fine, but the watcher is still ignoring the files that are not in our electron project.

Is it somehow possible to configure the watcher and add some additional folders to the list of watched files?

skhameneh commented 6 years ago

Somewhat related, filed electron-userland/electron-webpack/issues/183 attempting the same.

I have overridden watchOptions with a custom regex for ignore; the regex works but I am unable to debug. I have applied this config to devServer as well with no avail.

e.g.

  watchOptions: {
    ignored: [
      // Ignore all node_modules, EXCEPT module_name
      /node_modules([\\]+|\/)+(?!module_name)/,
      /module_name([\\]+|\/)node_modules/,
    ],
  },
skhameneh commented 6 years ago

I ended up using filewatcher-webpack-plugin.

Unfortunately there's no great way to selectively adjust plugins and this plugin breaks production compilation. I have to process arguments to reliably detect what is being built.

e.g.

const FilewatcherPlugin = require('filewatcher-webpack-plugin');

let PROCESS_ARGV = process.env.npm_config_argv;
if (PROCESS_ARGV) {
  PROCESS_ARGV = JSON.parse(PROCESS_ARGV);
}

const isDev = PROCESS_ARGV && PROCESS_ARGV.original &&
  (PROCESS_ARGV.original.indexOf('dev') !== -1);

module.exports = {
  // ...
  plugins: isDev ? [
    new FilewatcherPlugin({
      watchFileRegex: [require.resolve('module_name')],
    }),
  ] : [],
  // ...
};
tlenclos commented 6 years ago

Using this plugin is crashing the webpack process because of double compilation, did you solve this issue ?

hieuhlc commented 5 years ago

I have managed to work around this issue by moving the location of packages/* to inside src. Not so elegant but it'll work.

mjashanks commented 5 years ago

Hi there, I just created a PR (#291) that will give you much more control over your webpack config. I think it may help you - trying to get some people behind this :)