diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 1085d1e070f..fd033e0b97d 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -122,6 +122,7 @@ export enum BuiltinPluginName { EnableChunkLoadingPlugin = 'EnableChunkLoadingPlugin', EnableLibraryPlugin = 'EnableLibraryPlugin', EnableWasmLoadingPlugin = 'EnableWasmLoadingPlugin', + FetchCompileAsyncWasmPlugin = 'FetchCompileAsyncWasmPlugin', ChunkPrefetchPreloadPlugin = 'ChunkPrefetchPreloadPlugin', CommonJsChunkFormatPlugin = 'CommonJsChunkFormatPlugin', ArrayPushCallbackChunkFormatPlugin = 'ArrayPushCallbackChunkFormatPlugin', diff --git a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs index f5050efbfb0..ee24f1056c9 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs @@ -69,7 +69,9 @@ use rspack_plugin_size_limits::SizeLimitsPlugin; use rspack_plugin_swc_css_minimizer::SwcCssMinimizerRspackPlugin; use rspack_plugin_swc_js_minimizer::SwcJsMinimizerRspackPlugin; use rspack_plugin_warn_sensitive_module::WarnCaseSensitiveModulesPlugin; -use rspack_plugin_wasm::{enable_wasm_loading_plugin, AsyncWasmPlugin}; +use rspack_plugin_wasm::{ + enable_wasm_loading_plugin, AsyncWasmPlugin, FetchCompileAsyncWasmPlugin, +}; use rspack_plugin_web_worker_template::web_worker_template_plugin; use rspack_plugin_worker::WorkerPlugin; @@ -112,6 +114,7 @@ pub enum BuiltinPluginName { EnableChunkLoadingPlugin, EnableLibraryPlugin, EnableWasmLoadingPlugin, + FetchCompileAsyncWasmPlugin, ChunkPrefetchPreloadPlugin, CommonJsChunkFormatPlugin, ArrayPushCallbackChunkFormatPlugin, @@ -256,6 +259,9 @@ impl BuiltinPlugin { wasm_loading_type.as_str().into(), )); } + BuiltinPluginName::FetchCompileAsyncWasmPlugin => { + plugins.push(FetchCompileAsyncWasmPlugin::default().boxed()) + } BuiltinPluginName::ChunkPrefetchPreloadPlugin => { plugins.push(ChunkPrefetchPreloadPlugin::default().boxed()); } diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index f8e4ce7b175..276ec55dada 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -3164,6 +3164,17 @@ export type Falsy = z.infer; // @public (undocumented) const falsy: z.ZodUnion<[z.ZodLiteral, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>; +// @public (undocumented) +const FetchCompileAsyncWasmPlugin: { + new (): { + name: BuiltinPluginName; + _options: void; + affectedHooks: "make" | "compile" | "emit" | "afterEmit" | "invalid" | "done" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + raw(): BuiltinPlugin; + apply(compiler: Compiler_2): void; + }; +}; + // @public (undocumented) export type Filename = z.infer; @@ -8253,6 +8264,7 @@ declare namespace rspackExports { LoaderOptionsPlugin, LoaderTargetPlugin, NormalModuleReplacementPlugin, + web, node, electron, library, @@ -13350,6 +13362,15 @@ namespace Watchpack { } } +// @public (undocumented) +interface Web { + // (undocumented) + FetchCompileAsyncWasmPlugin: typeof FetchCompileAsyncWasmPlugin; +} + +// @public (undocumented) +export const web: Web; + // @public (undocumented) export type WebassemblyModuleFilename = z.infer; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index a1aec76f7fc..5d14293f1b1 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -1,4 +1,3 @@ -import fs from "fs"; /** * The following code is modified based on * https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Compiler.js diff --git a/packages/rspack/src/builtin-plugin/FetchCompileAsyncWasmPlugin.ts b/packages/rspack/src/builtin-plugin/FetchCompileAsyncWasmPlugin.ts new file mode 100644 index 00000000000..53df453e416 --- /dev/null +++ b/packages/rspack/src/builtin-plugin/FetchCompileAsyncWasmPlugin.ts @@ -0,0 +1,9 @@ +import { BuiltinPluginName } from "@rspack/binding"; + +import { create } from "./base"; + +export const FetchCompileAsyncWasmPlugin = create( + BuiltinPluginName.FetchCompileAsyncWasmPlugin, + () => {}, + "thisCompilation" +); diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 0af61108423..1b96f5eee8c 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -62,6 +62,7 @@ export * from "./SwcJsMinimizerPlugin"; export * from "./WarnCaseSensitiveModulesPlugin"; export * from "./WebWorkerTemplatePlugin"; export * from "./WorkerPlugin"; +export * from "./FetchCompileAsyncWasmPlugin"; ///// DEPRECATED ///// import { RawBuiltins } from "@rspack/binding"; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 55f0eff409b..de8f1c826de 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -100,6 +100,14 @@ export { LoaderOptionsPlugin } from "./lib/LoaderOptionsPlugin"; export { LoaderTargetPlugin } from "./lib/LoaderTargetPlugin"; export { NormalModuleReplacementPlugin } from "./lib/NormalModuleReplacementPlugin"; +import { FetchCompileAsyncWasmPlugin } from "./builtin-plugin"; +interface Web { + FetchCompileAsyncWasmPlugin: typeof FetchCompileAsyncWasmPlugin; +} +export const web: Web = { + FetchCompileAsyncWasmPlugin +}; + import { NodeTargetPlugin } from "./builtin-plugin"; import NodeEnvironmentPlugin from "./node/NodeEnvironmentPlugin"; import NodeTemplatePlugin from "./node/NodeTemplatePlugin"; diff --git a/website/components/PluginSupportStatusTable.tsx b/website/components/PluginSupportStatusTable.tsx index e958603109b..07f22db7a0e 100644 --- a/website/components/PluginSupportStatusTable.tsx +++ b/website/components/PluginSupportStatusTable.tsx @@ -372,11 +372,8 @@ const pluginSupportStatusList: PluginSupportStatus[] = [ }, { name: 'FetchCompileAsyncWasmPlugin', - status: SupportStatus.PartiallySupported, - notes: { - en: 'Temporarily not exported from the JavaScript side', - zh: '暂时未从 JavaScript 侧导出', - }, + url: '/plugins/webpack/fetch-compile-async-wasm-plugin', + status: SupportStatus.FullySupported, }, { name: 'FetchCompileWasmPlugin', diff --git a/website/docs/en/guide/features/web-workers.mdx b/website/docs/en/guide/features/web-workers.mdx index 9617f55b12f..c649f418756 100644 --- a/website/docs/en/guide/features/web-workers.mdx +++ b/website/docs/en/guide/features/web-workers.mdx @@ -49,3 +49,25 @@ The syntax was chosen to allow running code without bundler, it is also availabl - Not supported `/* webpackEntryOptions: { filename: "workers/[name].js" } */` magic comments ::: + +## worker-loader + + + +:::warning +worker-loader is provided only as a temporary solution to facilitate project migration to Rspack. It is recommended to use the `new Worker()` syntax instead. +::: + +Rspack also supports worker-loader. However, since [worker-loader](https://github.com/webpack-contrib/worker-loader) is no longer maintained, please use [worker-rspack-loader](https://github.com/rspack-contrib/worker-rspack-loader) as a replacement. + +Use [resolveLoader](/config/resolve-loader) to replace worker-loader with worker-rspack-loader: + +```js +module.exports = { + resolveLoader: { + alias: { + 'worker-loader': require.resolve('worker-rspack-loader'), + }, + }, +}; +``` diff --git a/website/docs/en/plugins/webpack/internal-plugins.mdx b/website/docs/en/plugins/webpack/internal-plugins.mdx index d5d96645abc..05ac15965b2 100644 --- a/website/docs/en/plugins/webpack/internal-plugins.mdx +++ b/website/docs/en/plugins/webpack/internal-plugins.mdx @@ -92,6 +92,14 @@ Chunks are loaded by `importScripts`. `options` are the output options. +### FetchCompileAsyncWasmPlugin + + + +This plugin is used to provide runtime code for WASM bundling and is often used together with a child compiler. + +`web.FetchCompileAsyncWasmPlugin()` + ## source Plugins affecting the source code of modules. diff --git a/website/docs/zh/guide/features/web-workers.mdx b/website/docs/zh/guide/features/web-workers.mdx index a5c84ea9fd5..26cea67498a 100644 --- a/website/docs/zh/guide/features/web-workers.mdx +++ b/website/docs/zh/guide/features/web-workers.mdx @@ -49,3 +49,25 @@ new Worker(new URL('./worker.js', import.meta.url), { - 不支持 `/* webpackEntryOptions: { filename: "workers/[name].js" } */` 魔法注释 ::: + +## worker-loader + + + +:::warning +worker-loader 仅供作为方便项目迁移至 Rspack 的临时方案,推荐使用 `new Worker()` 语法。 +::: + +Rspack 也支持了 worker-loader,不过由于 [worker-loader](https://github.com/webpack-contrib/worker-loader) 已不再维护,请使用 [worker-rspack-loader](https://github.com/rspack-contrib/worker-rspack-loader) 进行替换。 + +使用 [resolveLoader](/config/resolve-loader) 替换 worker-loader 为 worker-rspack-loader: + +```js +module.exports = { + resolveLoader: { + alias: { + 'worker-loader': require.resolve('worker-rspack-loader'), + }, + }, +}; +``` diff --git a/website/docs/zh/plugins/webpack/internal-plugins.mdx b/website/docs/zh/plugins/webpack/internal-plugins.mdx index 13a8218735b..c827f7ccfc8 100644 --- a/website/docs/zh/plugins/webpack/internal-plugins.mdx +++ b/website/docs/zh/plugins/webpack/internal-plugins.mdx @@ -92,6 +92,14 @@ import WebpackLicense from '@components/webpack-license'; `options` 是输出配置。 +### FetchCompileAsyncWasmPlugin + + + +用来提供 WASM 打包的运行时代码,经常配合 childCompiler 一起使用。 + +`web.FetchCompileAsyncWasmPlugin()` + ## source 影响模块源代码的插件。