momocow / webpack-userscript

A Webpack plugin for userscript projects. 🙈
https://cow.moe/webpack-userscript/
MIT License
200 stars 21 forks source link

Using plugin with Webpack 5 causes deprecation warning #42

Closed carlomorelli closed 1 year ago

carlomorelli commented 3 years ago

Hi, I'm experimenting with Webpack 5.0.0 and webpack-userscript plugin (version 2.5.6). I see the following at terminal when launching webpack:

node:30372) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.

The output is correctly generated anyway. This is my webpack.config.file:

module.exports = {
   ...
   plugins: [
      new WebpackUserscript()
   ]
}
momocow commented 3 years ago

Thanks for reporting the issue. I'll check about Webpack 5.

vitoyucepi commented 3 years ago

Also it's required to update types after migration to webpack: ^5.0.0.

diff --git a/lib/index.d.ts b/lib/index.d.ts
index 36f9c49..76b29ae 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,4 +1,4 @@
-import {Compiler, Plugin} from 'webpack';
+import {Compiler, WebpackPluginInstance} from 'webpack';

 declare namespace WebpackUserscript {
   type WebpackUserscriptOptions =
@@ -208,7 +208,7 @@ declare namespace WebpackUserscript {
   }
 }

-declare class WebpackUserscript extends Plugin {
+declare class WebpackUserscript implements WebpackPluginInstance {
   constructor(options?: WebpackUserscript.WebpackUserscriptOptions);

   apply(compiler: Compiler): void;

Ref: webpack/webpack#11630

inazuma-bot commented 1 year ago

:tada: This issue has been resolved in version 3.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: