1

I have the following function:

export default function(path, urlKey = 'static') {

    if (urlKey === 'static') {
        path = require(`~/static${path}`).default;
    }

    urlKey = Object.keys(config.app.urls).includes(urlKey) ? urlKey : 'static';

    return (config.app.urls[urlKey] + '/' + path).replace(/([^:]\/)\/+/g, "$1");

};

As you can see, I am using a dynamic require which I believe utilises require.context. When my webpack bundles, it builds all the files in the static folder. The ~/static part of the path is an alias to my static folder in the root directory.

When using the watch mode of webpack, the bundling goes into an endless loop.

I have tried various things such as watchOptions.ignored and the WatchIgnorePlugin but neither of these have worked.

These are my two attempts with the above solutions:

watchOptions: {
    ignored: /static/
}

and

plugins:[
    new WatchIgnorePlugin([
        path.resolve(__dirname, '..', 'static')
    ]),
]

Can anyone suggest what I am missing here?

Ben Carey
  • 16,540
  • 19
  • 87
  • 169
Giorgi Lagidze
  • 773
  • 4
  • 24

1 Answers1

0

I have also been experiencing the issue of endless rebuilds. After many tries, I was finally able to exclude the static folder by using the WatchIgnorePlugin in my webpack.dev.config.js:

devWebpackConfig = merge(baseWebpackConfig, {
  ...
  plugins: [
    ...
    new webpack.WatchIgnorePlugin([
      path.resolve(__dirname, '../static')
    ])
  
vekinox
  • 41
  • 4