web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.38k stars 543 forks source link

Support compilation.hooks.optimizeAssets #4938

Closed jeromehan closed 1 month ago

jeromehan commented 10 months ago

System Info

null

Details

@unocss/webpack@0.58.0

compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
       compilation.hooks.optimizeAssets.tapPromise(PLUGIN_NAME, async () => {
           ...
       });
});

need compilation.hooks.optimizeAssets API

Reproduce link

No response

Reproduce Steps

  1. const UnoCSS = require('@unocss/webpack').default
  2. plugins: [ UnoCSS()]
faga295 commented 10 months ago

I can help to support this

burhanuday commented 10 months ago

While this is needed for a few plugins to work, the optimizeAssets hook is deprecated and to be removed in Webpack 6 @hardfist In webpack 5, optimizeAssets is just a shim over the processAssets hook. should i do the same in Rspack as well?

hardfist commented 10 months ago

@burhanuday thank you for this helpful information, I think we can hold on the optimizeAssets implementation until we really need,@jeromehan can you help file a issue | PR in @unocss/webpack@0.58.0 and see whether they're willing to replace it with processAssets implementation

hardfist commented 10 months ago

@burhanuday https://github.com/webpack/webpack/blob/87660921808566ef3b8796f8df61bd79fc026108/lib/Compilation.js#L817 it seems webpack only deprecate it in source code comment, the users are not aware this hook is deprecated, maybe we should give deprecate warning to plugin author in webpack, and BTW is there any documentation or issue tracking the deprecate the plan of webpack 6(what will be deprecated or removed in webpack 6)

burhanuday commented 10 months ago

According to the description of the PR https://github.com/webpack/webpack/pull/10876, it should emit a deprecation warning in the console. Not aware of any issue where this is tracked. Pulling in @alexander-akait to see if he is aware I'll raise a PR to update the docs since it is missed there

alexander-akait commented 9 months ago

@hardfist Yeah, you are right, but we are avouding deprecation messages because it was implemented/refactored in the minor version and adding the deprecation message will make mess in console, but for webpack 6 we will add soft deprecation (still a lot of plugins use it, but we will check it before), so I think better do not implement optimizeAssets for rspack

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

xc2 commented 7 months ago

bump

xc2 commented 7 months ago

@unocss/webpack will use processAssets hooks in the next version. Stay tuned for updates.

and you also need to create an empty file named __uno.css for the plugin to work with rspack.

example: https://github.com/xc2/rspack-usecases/tree/4be82c900bd6af47ada2c63f53922b731bb63a28/rspack/unocss-webpack

zhtyytg commented 6 months ago

hi there, I used to use postcss to support unocss, but recently I want to switch to @unocss/webpack. Do you solve it?

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

ljianc commented 3 months ago

@unocss/webpack will use processAssets hooks in the next version. Stay tuned for updates.

and you also need to create an empty file named __uno.css for the plugin to work with rspack.

example: https://github.com/xc2/rspack-usecases/tree/4be82c900bd6af47ada2c63f53922b731bb63a28/rspack/unocss-webpack

这样当npm run dev的时候就生成一次css,此后再修改className就不会再生成了

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

hardfist commented 1 month ago

close this issue since we don't plan to support hooks.optimizeAssets hooks