rspack
rspack copied to clipboard
[Feature]: port GoogleFontsWebpackPlugin or WebfontDownloadVitePlugin
What problem does this feature solve?
TLDR: Ship webfonts together with application
Migrating from Webpack, users want to keep all plugins they depend on. For us, one such plugin is Google Fonts Webpack Plugin. We depend on it, because we ship our application into multiple corporate environments, that have WAF or other policies that prevent loading webfonts directly - so we have to ship webfonts with our application. It worked with RsPack 1.3.4 after doing a small patch, but after updating it broke again (compilation.chunks.add is not a function).
There is an even better plugin for Vite - Webfont Download Vite Plugin - which works with multiple webfont providers and does the font download directly without a middle website like the webpack plugin.
Additional note is that for RsPack to compete with Webpack & Vite, it should provide the same functions at minimum.
What does the proposed API of configuration look like?
see Webpack plugin or Vite plugin.
The mix of those, for example:
{
// ...
plugins: [
pluginWebfontDownload({
fonts: [
'https://fonts.googleapis.com/css2?family=Fira+Code&display=swap',
{ provider: FontProviders.Fontshare, family: "Roboto", variants: [ "400", "700italic" ], display: "block" }
],
}),
}
Do we support compilation.chunks.add ? cc @SyMind
I now need to have these two patches in place
- compilation.chunks.add(this.chunk);
+ // fix rspack compatibility
+ // compilation.chunks.add(this.chunk);
+ compilation.chunks[this.options.name] = this.chunk;
- addFile(cssFile, new RawSource(css));
+ // fix for RsPack: use compilers RawSource, not the bundled one with this plugin
+ addFile(cssFile, new compiler.webpack.sources.RawSource(css));
@vitexikora I think the plugin can just use emitAsset() to refactor.