Webpack 5 support
Opened this issue · 4 comments
Hi there, So i'm testing out Webpacker 6 which uses webpack 5 - I'm having trouble initializing the loader.
module.exports = {
test: /\.erb$/,
enforce: "pre",
exclude: /node_modules/,
use: [{
loader: "rails-erb-loader",
options: {
runner: (/^win/.test(process.platform) ? "ruby " : "") + "bin/rails runner",
env: {
...process.env,
DISABLE_SPRING: 1,
},
},
}],
}
Which gives me this error
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'use'. These properties are valid:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, experiments?, externals?, externalsPresets?, externalsType?, ignoreWarnings?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, snapshot?, stats?, target?, watch?, watchOptions? }
-> Options object as provided by the user.
For typos: please correct them.
For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
plugins: [
new webpack.LoaderOptionsPlugin({
// test: /\.xxx$/, // may apply this only for some modules
options: {
use: …
}
})
]
Any ideas how to adapt the loader? Do you need to do work to support the new webpack 5 plugin API?
Any ideas how to adapt the loader?
First step is to add webpack 5 to the test suite here:
Lines 16 to 18 in 233db82
Lines 15 to 17 in 233db82
However, it sounds as though you're simply providing the options to rails-erb-loader is an old way that is not longer valid:
configuration has an unknown property 'use'.
Additionally it sounds like the API for reading options may have changed:
For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration. Loaders should be updated to allow passing options via loader options in module.rules.
Note that in making required changes (if any) we will also need to continue to support older versions of webpack.
Additionally for this change to be complete we will need to update the README to show the current recommended way to configure webpack 5.
Do you need to do work to support the new webpack 5 plugin API?
I myself will not be making this change, but will happily accept a PR that does so, provided the above is included, or explanation is given as to why it was not required.
Webpacker 6 has already included a default rule for .erb
files with rails-erb-loader
as loader
(When the module rails-erb-loader
can be resolved)
@PikachuEXE Ah this is correct, and yes it 'just works' in webpacker 6 without any user config at all - thank you very much.
Reopening until we can confirm compatibility with webpack 5.