webpack-inject-plugin icon indicating copy to clipboard operation
webpack-inject-plugin copied to clipboard

Webpack 5 support

Open donferi opened this issue 5 years ago • 4 comments
trafficstars

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

donferi avatar Oct 20 '20 16:10 donferi

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 🙏

deini avatar Oct 26 '20 19:10 deini

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!

lobsterkatie avatar Oct 15 '21 08:10 lobsterkatie

Looks like someone has done some work on Webpack5 support already: https://github.com/bpnetguy/webpack-inject-plugin

@bpnetguy

flakey-bit avatar Oct 04 '22 06:10 flakey-bit

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"]

inject-webpack

zhangHongEn avatar Nov 14 '22 03:11 zhangHongEn