webpack-inject-plugin
webpack-inject-plugin copied to clipboard
Webpack 5 support
Trying to upgrade a repo to use webpack 5 but I keep getting this:
ERROR in (./node_modules/webpack-inject-plugin/dist/webpack-inject-plugin.loader.js?id=webpack-inject-module-2!)
Module build failed (from ./node_modules/file-loader/dist/cjs.js):
TypeError: argument 'value' must be either string of Buffer
I'm experiencing the same issue when combined with file-loader + oneOf.
Simplified repro on webpack 5, modified example/webpack.config.js to:
const InjectPlugin = require('..').default;
module.exports = {
entry: './entry.js',
mode: 'development',
plugins: [
new InjectPlugin(() => `console.log('hello world');`),
new InjectPlugin(() => `console.log('second injected code');`)
],
module: {
rules: [
{
oneOf: [
{
exclude: [/webpack-inject/],
loader: require.resolve('file-loader'),
}
]
}
]
}
};
Seems like now its trying to use file-loader on webpack-inject-plugin.loader.js?id=webpack-inject-module-1. Tried excluding it but haven't been able to get it to work yet.
Will try to investigate a bit more, lmk if you have any ideas @adierkens 🙏
To support webpack 5 it'll also be necessary to account for the possibility of entry descriptor syntax - see https://webpack.js.org/configuration/entry-context/#entry-descriptor.
Cheers!
Looks like someone has done some work on Webpack5 support already: https://github.com/bpnetguy/webpack-inject-plugin
@bpnetguy
I also need this plugin in webpack5, so I have to implement a version myself, Code injection can be performed by scopes ["entry", "remoteEntry", "exposesEntry"]