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?