@rspack/core 0.6.5-canary-2456d69-20240515093621 → 0.6.5-canary-5042eed-20240515115707

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,7 @@ export declare class Watching {
24
24
  watch(files: Iterable<string>, dirs: Iterable<string>, missing: Iterable<string>): void;
25
25
  close(callback?: () => void): void;
26
26
  invalidate(callback?: Callback<Error, void>): void;
27
+ lazyCompilationInvalidate(files: Set<string>): void;
27
28
  /**
28
29
  * The reason why this is _done instead of #done, is that in Webpack,
29
30
  * it will rewrite this function to another function
package/dist/Watching.js CHANGED
@@ -160,6 +160,9 @@ class Watching {
160
160
  this.onChange();
161
161
  __classPrivateFieldGet(this, _Watching_instances, "m", _Watching_invalidate).call(this);
162
162
  }
163
+ lazyCompilationInvalidate(files) {
164
+ __classPrivateFieldGet(this, _Watching_instances, "m", _Watching_invalidate).call(this, new Map(), new Map(), files, new Set());
165
+ }
163
166
  _done(error, compilation) {
164
167
  this.running = false;
165
168
  let stats = undefined;
@@ -38,7 +38,7 @@ function createBuiltinPlugin(name, options) {
38
38
  }
39
39
  exports.createBuiltinPlugin = createBuiltinPlugin;
40
40
  function create(name, resolve,
41
- // `affectedHooks` is used to inform `createChildCompile` about which builtin plugin can be reversed.
41
+ // `affectedHooks` is used to inform `createChildCompile` about which builtin plugin can be reserved.
42
42
  // However, this has a drawback as it doesn't represent the actual condition but merely serves as an indicator.
43
43
  affectedHooks) {
44
44
  class Plugin extends RspackBuiltinPlugin {
@@ -58,6 +58,7 @@ export * from "./SwcJsMinimizerPlugin";
58
58
  export * from "./WarnCaseSensitiveModulesPlugin";
59
59
  export * from "./WebWorkerTemplatePlugin";
60
60
  export * from "./WorkerPlugin";
61
+ export * from "./lazy-compilation/plugin";
61
62
  import { RawBuiltins } from "@rspack/binding";
62
63
  import { RspackOptionsNormalized } from "..";
63
64
  export interface Builtins {
@@ -76,6 +76,7 @@ __exportStar(require("./SwcJsMinimizerPlugin"), exports);
76
76
  __exportStar(require("./WarnCaseSensitiveModulesPlugin"), exports);
77
77
  __exportStar(require("./WebWorkerTemplatePlugin"), exports);
78
78
  __exportStar(require("./WorkerPlugin"), exports);
79
+ __exportStar(require("./lazy-compilation/plugin"), exports);
79
80
  function resolveTreeShaking(treeShaking, production) {
80
81
  return treeShaking !== undefined
81
82
  ? treeShaking.toString()
@@ -0,0 +1,50 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ import type { IncomingMessage, ServerResponse, ServerOptions as ServerOptionsImport } from "http";
6
+ import type { ListenOptions, Server } from "net";
7
+ import type { Compiler } from "../..";
8
+ import type { SecureContextOptions, TlsOptions } from "tls";
9
+ export interface LazyCompilationDefaultBackendOptions {
10
+ /**
11
+ * A custom client.
12
+ */
13
+ client?: string;
14
+ /**
15
+ * Specifies where to listen to from the server.
16
+ */
17
+ listen?: number | ListenOptions | ((server: Server) => void);
18
+ /**
19
+ * Specifies the protocol the client should use to connect to the server.
20
+ */
21
+ protocol?: "http" | "https";
22
+ /**
23
+ * Specifies how to create the server handling the EventSource requests.
24
+ */
25
+ server?: ServerOptionsImport<typeof IncomingMessage> | ServerOptionsHttps<typeof IncomingMessage, typeof ServerResponse> | (() => Server);
26
+ }
27
+ export type ServerOptionsHttps<Request extends typeof IncomingMessage = typeof IncomingMessage, Response extends typeof ServerResponse = typeof ServerResponse> = SecureContextOptions & TlsOptions & ServerOptionsImport<Request, Response>;
28
+ declare const getBackend: (options: Omit<LazyCompilationDefaultBackendOptions, "client"> & {
29
+ client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>;
30
+ }) => (compiler: Compiler, callback: (err: any, obj?: {
31
+ dispose: (callback: (err: any) => void) => void;
32
+ module: (args: {
33
+ module: string;
34
+ path: string;
35
+ }) => {
36
+ data: string;
37
+ client: string;
38
+ active: boolean;
39
+ };
40
+ } | undefined) => void) => void;
41
+ export default getBackend;
42
+ export declare function dispose(callback: any): void;
43
+ export declare function moduleImpl(args: {
44
+ module: string;
45
+ path: string;
46
+ }): {
47
+ active: boolean;
48
+ data: string;
49
+ client: string;
50
+ };
@@ -0,0 +1,139 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.moduleImpl = exports.dispose = void 0;
8
+ const getBackend = (options) => (compiler, callback) => {
9
+ const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
10
+ const activeModules = new Map();
11
+ const filesByKey = new Map();
12
+ const prefix = "/lazy-compilation-using-";
13
+ const isHttps = options.protocol === "https" ||
14
+ (typeof options.server === "object" &&
15
+ ("key" in options.server || "pfx" in options.server));
16
+ const createServer = typeof options.server === "function"
17
+ ? options.server
18
+ : (() => {
19
+ const http = isHttps ? require("https") : require("http");
20
+ return http.createServer.bind(http, options.server);
21
+ })();
22
+ const listen = typeof options.listen === "function"
23
+ ? options.listen
24
+ : (server) => {
25
+ let listen = options.listen;
26
+ if (typeof listen === "object" && !("port" in listen))
27
+ listen = { ...listen, port: undefined };
28
+ server.listen(listen);
29
+ };
30
+ const protocol = options.protocol || (isHttps ? "https" : "http");
31
+ const requestListener = (req, res) => {
32
+ const keys = req.url.slice(prefix.length).split("@");
33
+ req.socket.on("close", () => {
34
+ setTimeout(() => {
35
+ for (const key of keys) {
36
+ const oldValue = activeModules.get(key) || 0;
37
+ activeModules.set(key, oldValue - 1);
38
+ if (oldValue === 1) {
39
+ logger.log(`${key} is no longer in use. Next compilation will skip this module.`);
40
+ }
41
+ }
42
+ }, 120000);
43
+ });
44
+ req.socket.setNoDelay(true);
45
+ res.writeHead(200, {
46
+ "content-type": "text/event-stream",
47
+ "Access-Control-Allow-Origin": "*",
48
+ "Access-Control-Allow-Methods": "*",
49
+ "Access-Control-Allow-Headers": "*"
50
+ });
51
+ res.write("\n");
52
+ const moduleActivated = [];
53
+ for (const key of keys) {
54
+ const oldValue = activeModules.get(key) || 0;
55
+ activeModules.set(key, oldValue + 1);
56
+ if (oldValue === 0) {
57
+ logger.log(`${key} is now in use and will be compiled.`);
58
+ moduleActivated.push(key);
59
+ }
60
+ }
61
+ if (moduleActivated.length && compiler.watching) {
62
+ compiler.watching.lazyCompilationInvalidate(new Set(moduleActivated.map(key => filesByKey.get(key))));
63
+ }
64
+ };
65
+ const server = createServer();
66
+ server.on("request", requestListener);
67
+ let isClosing = false;
68
+ const sockets = new Set();
69
+ server.on("connection", socket => {
70
+ sockets.add(socket);
71
+ socket.on("close", () => {
72
+ sockets.delete(socket);
73
+ });
74
+ if (isClosing)
75
+ socket.destroy();
76
+ });
77
+ server.on("clientError", e => {
78
+ if (e.message !== "Server is disposing")
79
+ logger.warn(e);
80
+ });
81
+ server.on("listening", (err) => {
82
+ if (err)
83
+ return callback(err);
84
+ const addr = server.address();
85
+ if (typeof addr === "string")
86
+ throw new Error("addr must not be a string");
87
+ const urlBase = addr.address === "::" || addr.address === "0.0.0.0"
88
+ ? `${protocol}://localhost:${addr.port}`
89
+ : addr.family === "IPv6"
90
+ ? `${protocol}://[${addr.address}]:${addr.port}`
91
+ : `${protocol}://${addr.address}:${addr.port}`;
92
+ logger.log(`Server-Sent-Events server for lazy compilation open at ${urlBase}.`);
93
+ const result = {
94
+ dispose(callback) {
95
+ isClosing = true;
96
+ // Removing the listener is a workaround for a memory leak in node.js
97
+ server.off("request", requestListener);
98
+ server.close(err => {
99
+ callback(err);
100
+ });
101
+ for (const socket of sockets) {
102
+ socket.destroy(new Error("Server is disposing"));
103
+ }
104
+ },
105
+ module({ module: originalModule, path }) {
106
+ const key = `${encodeURIComponent(originalModule.replace(/\\/g, "/").replace(/@/g, "_")).replace(/%(2F|3A|24|26|2B|2C|3B|3D|3A)/g, decodeURIComponent)}`;
107
+ filesByKey.set(key, path);
108
+ const active = activeModules.get(key) > 0;
109
+ return {
110
+ client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
111
+ data: key,
112
+ active
113
+ };
114
+ }
115
+ };
116
+ state.module = result.module;
117
+ state.dispose = result.dispose;
118
+ callback(null, result);
119
+ });
120
+ listen(server);
121
+ };
122
+ exports.default = getBackend;
123
+ function unimplemented() {
124
+ throw new Error("access before initialization");
125
+ }
126
+ const state = {
127
+ module: unimplemented,
128
+ dispose: unimplemented
129
+ };
130
+ function dispose(callback) {
131
+ state.dispose(callback);
132
+ state.dispose = unimplemented;
133
+ state.module = unimplemented;
134
+ }
135
+ exports.dispose = dispose;
136
+ function moduleImpl(args) {
137
+ return state.module(args);
138
+ }
139
+ exports.moduleImpl = moduleImpl;
@@ -0,0 +1,30 @@
1
+ import { BuiltinPluginName, JsModule, RawRegexMatcher } from "@rspack/binding";
2
+ export declare const BuiltinLazyCompilationPlugin: {
3
+ new (module: (args: {
4
+ module: string;
5
+ path: string;
6
+ }) => {
7
+ active: boolean;
8
+ data: string;
9
+ client: string;
10
+ }, cacheable: boolean, entries: boolean, imports: boolean, test?: RawRegexMatcher | ((m: JsModule) => boolean) | undefined): {
11
+ name: BuiltinPluginName;
12
+ _options: {
13
+ module: (args: {
14
+ module: string;
15
+ path: string;
16
+ }) => {
17
+ active: boolean;
18
+ data: string;
19
+ client: string;
20
+ };
21
+ cacheable: boolean;
22
+ imports: boolean;
23
+ entries: boolean;
24
+ test: RawRegexMatcher | ((m: JsModule) => boolean) | undefined;
25
+ };
26
+ affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
27
+ raw(): import("@rspack/binding").BuiltinPlugin;
28
+ apply(compiler: import("../../Compiler").Compiler): void;
29
+ };
30
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuiltinLazyCompilationPlugin = void 0;
4
+ const binding_1 = require("@rspack/binding");
5
+ const base_1 = require("../base");
6
+ exports.BuiltinLazyCompilationPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.LazyCompilationPlugin, (module, cacheable, entries, imports, test) => ({ module, cacheable, imports, entries, test }), "thisCompilation");
@@ -0,0 +1,13 @@
1
+ import type { Compiler } from "../..";
2
+ import { LazyCompilationDefaultBackendOptions } from "./backend";
3
+ import { JsModule, RawRegexMatcher } from "@rspack/binding";
4
+ export default class LazyCompilationPlugin {
5
+ cacheable: boolean;
6
+ entries: boolean;
7
+ imports: boolean;
8
+ test?: RawRegexMatcher | ((m: JsModule) => boolean);
9
+ backend?: LazyCompilationDefaultBackendOptions;
10
+ constructor(cacheable: boolean, entries: boolean, imports: boolean, test?: RawRegexMatcher | ((m: JsModule) => boolean), backend?: LazyCompilationDefaultBackendOptions);
11
+ apply(compiler: Compiler): void;
12
+ }
13
+ export { LazyCompilationPlugin };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.LazyCompilationPlugin = void 0;
27
+ const lazyCompilation_1 = require("./lazyCompilation");
28
+ const backend_1 = __importStar(require("./backend"));
29
+ class LazyCompilationPlugin {
30
+ constructor(cacheable, entries, imports, test, backend) {
31
+ this.cacheable = cacheable;
32
+ this.entries = entries;
33
+ this.imports = imports;
34
+ this.test = test;
35
+ this.backend = backend;
36
+ }
37
+ apply(compiler) {
38
+ const backend = (0, backend_1.default)({
39
+ ...this.backend,
40
+ client: require.resolve(`../../../hot/lazy-compilation-${compiler.options.externalsPresets.node ? "node" : "web"}.js`)
41
+ });
42
+ new lazyCompilation_1.BuiltinLazyCompilationPlugin(backend_1.moduleImpl, this.cacheable, this.entries, this.imports, this.test).apply(compiler);
43
+ let initialized = false;
44
+ compiler.hooks.beforeCompile.tapAsync("LazyCompilationPlugin", (_params, callback) => {
45
+ if (initialized)
46
+ return callback();
47
+ backend(compiler, (err, result) => {
48
+ if (err)
49
+ return callback(err);
50
+ initialized = true;
51
+ callback();
52
+ });
53
+ });
54
+ compiler.hooks.shutdown.tapAsync("LazyCompilationPlugin", callback => {
55
+ (0, backend_1.dispose)(callback);
56
+ });
57
+ }
58
+ }
59
+ exports.default = LazyCompilationPlugin;
60
+ exports.LazyCompilationPlugin = LazyCompilationPlugin;
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type { Compilation } from "../Compilation";
11
- import type { AssetModuleFilename, Bail, Builtins, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LibraryOptions, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
11
+ import type { AssetModuleFilename, Bail, Builtins, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LibraryOptions, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath, LazyCompilationOptions } from "./zod";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
13
  export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
14
  export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
@@ -78,7 +78,7 @@ export interface ModuleOptionsNormalized {
78
78
  noParse?: NoParseOption;
79
79
  }
80
80
  export interface ExperimentsNormalized {
81
- lazyCompilation?: boolean;
81
+ lazyCompilation?: false | LazyCompilationOptions;
82
82
  asyncWebAssembly?: boolean;
83
83
  outputModule?: boolean;
84
84
  topLevelAwait?: boolean;
@@ -190,7 +190,8 @@ const getNormalizedRspackOptions = (config) => {
190
190
  performance: config.performance,
191
191
  plugins: nestedArray(config.plugins, p => [...p]),
192
192
  experiments: nestedConfig(config.experiments, experiments => ({
193
- ...experiments
193
+ ...experiments,
194
+ lazyCompilation: optionalNestedConfig(experiments.lazyCompilation, options => (options === true ? {} : options))
194
195
  })),
195
196
  watch: config.watch,
196
197
  watchOptions: cloneObject(config.watchOptions),
@@ -4502,8 +4502,34 @@ declare const rspackFutureOptions: z.ZodObject<{
4502
4502
  } | undefined;
4503
4503
  }>;
4504
4504
  export type RspackFutureOptions = z.infer<typeof rspackFutureOptions>;
4505
+ declare const lazyCompilationOptions: z.ZodObject<{
4506
+ imports: z.ZodOptional<z.ZodBoolean>;
4507
+ entries: z.ZodOptional<z.ZodBoolean>;
4508
+ test: z.ZodOptional<z.ZodUnion<[z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Module, z.ZodTypeDef, Module>], z.ZodUnknown>, z.ZodBoolean>]>>;
4509
+ }, "strip", z.ZodTypeAny, {
4510
+ imports?: boolean | undefined;
4511
+ entries?: boolean | undefined;
4512
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4513
+ }, {
4514
+ imports?: boolean | undefined;
4515
+ entries?: boolean | undefined;
4516
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4517
+ }>;
4518
+ export type LazyCompilationOptions = z.infer<typeof lazyCompilationOptions>;
4505
4519
  declare const experiments: z.ZodObject<{
4506
- lazyCompilation: z.ZodOptional<z.ZodBoolean>;
4520
+ lazyCompilation: z.ZodUnion<[z.ZodOptional<z.ZodBoolean>, z.ZodObject<{
4521
+ imports: z.ZodOptional<z.ZodBoolean>;
4522
+ entries: z.ZodOptional<z.ZodBoolean>;
4523
+ test: z.ZodOptional<z.ZodUnion<[z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Module, z.ZodTypeDef, Module>], z.ZodUnknown>, z.ZodBoolean>]>>;
4524
+ }, "strip", z.ZodTypeAny, {
4525
+ imports?: boolean | undefined;
4526
+ entries?: boolean | undefined;
4527
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4528
+ }, {
4529
+ imports?: boolean | undefined;
4530
+ entries?: boolean | undefined;
4531
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4532
+ }>]>;
4507
4533
  asyncWebAssembly: z.ZodOptional<z.ZodBoolean>;
4508
4534
  outputModule: z.ZodOptional<z.ZodBoolean>;
4509
4535
  topLevelAwait: z.ZodOptional<z.ZodBoolean>;
@@ -4535,7 +4561,11 @@ declare const experiments: z.ZodObject<{
4535
4561
  } | undefined;
4536
4562
  }>>;
4537
4563
  }, "strict", z.ZodTypeAny, {
4538
- lazyCompilation?: boolean | undefined;
4564
+ lazyCompilation?: boolean | {
4565
+ imports?: boolean | undefined;
4566
+ entries?: boolean | undefined;
4567
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4568
+ } | undefined;
4539
4569
  asyncWebAssembly?: boolean | undefined;
4540
4570
  outputModule?: boolean | undefined;
4541
4571
  topLevelAwait?: boolean | undefined;
@@ -4549,7 +4579,11 @@ declare const experiments: z.ZodObject<{
4549
4579
  } | undefined;
4550
4580
  } | undefined;
4551
4581
  }, {
4552
- lazyCompilation?: boolean | undefined;
4582
+ lazyCompilation?: boolean | {
4583
+ imports?: boolean | undefined;
4584
+ entries?: boolean | undefined;
4585
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4586
+ } | undefined;
4553
4587
  asyncWebAssembly?: boolean | undefined;
4554
4588
  outputModule?: boolean | undefined;
4555
4589
  topLevelAwait?: boolean | undefined;
@@ -5183,7 +5217,19 @@ export declare const rspackOptions: z.ZodObject<{
5183
5217
  target: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["web", "webworker", "es3", "es5", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021", "es2022", "browserslist"]>, z.ZodLiteral<"node">]>, z.ZodLiteral<"async-node">]>, z.ZodType<`node${number}`, z.ZodTypeDef, `node${number}`>]>, z.ZodType<`async-node${number}`, z.ZodTypeDef, `async-node${number}`>]>, z.ZodType<`node${number}.${number}`, z.ZodTypeDef, `node${number}.${number}`>]>, z.ZodType<`async-node${number}.${number}`, z.ZodTypeDef, `async-node${number}.${number}`>]>, z.ZodLiteral<"electron-main">]>, z.ZodType<`electron${number}-main`, z.ZodTypeDef, `electron${number}-main`>]>, z.ZodType<`electron${number}.${number}-main`, z.ZodTypeDef, `electron${number}.${number}-main`>]>, z.ZodLiteral<"electron-renderer">]>, z.ZodType<`electron${number}-renderer`, z.ZodTypeDef, `electron${number}-renderer`>]>, z.ZodType<`electron${number}.${number}-renderer`, z.ZodTypeDef, `electron${number}.${number}-renderer`>]>, z.ZodLiteral<"electron-preload">]>, z.ZodType<`electron${number}-preload`, z.ZodTypeDef, `electron${number}-preload`>]>, z.ZodType<`electron${number}.${number}-preload`, z.ZodTypeDef, `electron${number}.${number}-preload`>]>]>, z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["web", "webworker", "es3", "es5", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021", "es2022", "browserslist"]>, z.ZodLiteral<"node">]>, z.ZodLiteral<"async-node">]>, z.ZodType<`node${number}`, z.ZodTypeDef, `node${number}`>]>, z.ZodType<`async-node${number}`, z.ZodTypeDef, `async-node${number}`>]>, z.ZodType<`node${number}.${number}`, z.ZodTypeDef, `node${number}.${number}`>]>, z.ZodType<`async-node${number}.${number}`, z.ZodTypeDef, `async-node${number}.${number}`>]>, z.ZodLiteral<"electron-main">]>, z.ZodType<`electron${number}-main`, z.ZodTypeDef, `electron${number}-main`>]>, z.ZodType<`electron${number}.${number}-main`, z.ZodTypeDef, `electron${number}.${number}-main`>]>, z.ZodLiteral<"electron-renderer">]>, z.ZodType<`electron${number}-renderer`, z.ZodTypeDef, `electron${number}-renderer`>]>, z.ZodType<`electron${number}.${number}-renderer`, z.ZodTypeDef, `electron${number}.${number}-renderer`>]>, z.ZodLiteral<"electron-preload">]>, z.ZodType<`electron${number}-preload`, z.ZodTypeDef, `electron${number}-preload`>]>, z.ZodType<`electron${number}.${number}-preload`, z.ZodTypeDef, `electron${number}.${number}-preload`>]>, "many">]>>;
5184
5218
  mode: z.ZodOptional<z.ZodEnum<["development", "production", "none"]>>;
5185
5219
  experiments: z.ZodOptional<z.ZodObject<{
5186
- lazyCompilation: z.ZodOptional<z.ZodBoolean>;
5220
+ lazyCompilation: z.ZodUnion<[z.ZodOptional<z.ZodBoolean>, z.ZodObject<{
5221
+ imports: z.ZodOptional<z.ZodBoolean>;
5222
+ entries: z.ZodOptional<z.ZodBoolean>;
5223
+ test: z.ZodOptional<z.ZodUnion<[z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodType<Module, z.ZodTypeDef, Module>], z.ZodUnknown>, z.ZodBoolean>]>>;
5224
+ }, "strip", z.ZodTypeAny, {
5225
+ imports?: boolean | undefined;
5226
+ entries?: boolean | undefined;
5227
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5228
+ }, {
5229
+ imports?: boolean | undefined;
5230
+ entries?: boolean | undefined;
5231
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5232
+ }>]>;
5187
5233
  asyncWebAssembly: z.ZodOptional<z.ZodBoolean>;
5188
5234
  outputModule: z.ZodOptional<z.ZodBoolean>;
5189
5235
  topLevelAwait: z.ZodOptional<z.ZodBoolean>;
@@ -5215,7 +5261,11 @@ export declare const rspackOptions: z.ZodObject<{
5215
5261
  } | undefined;
5216
5262
  }>>;
5217
5263
  }, "strict", z.ZodTypeAny, {
5218
- lazyCompilation?: boolean | undefined;
5264
+ lazyCompilation?: boolean | {
5265
+ imports?: boolean | undefined;
5266
+ entries?: boolean | undefined;
5267
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5268
+ } | undefined;
5219
5269
  asyncWebAssembly?: boolean | undefined;
5220
5270
  outputModule?: boolean | undefined;
5221
5271
  topLevelAwait?: boolean | undefined;
@@ -5229,7 +5279,11 @@ export declare const rspackOptions: z.ZodObject<{
5229
5279
  } | undefined;
5230
5280
  } | undefined;
5231
5281
  }, {
5232
- lazyCompilation?: boolean | undefined;
5282
+ lazyCompilation?: boolean | {
5283
+ imports?: boolean | undefined;
5284
+ entries?: boolean | undefined;
5285
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5286
+ } | undefined;
5233
5287
  asyncWebAssembly?: boolean | undefined;
5234
5288
  outputModule?: boolean | undefined;
5235
5289
  topLevelAwait?: boolean | undefined;
@@ -6661,7 +6715,11 @@ export declare const rspackOptions: z.ZodObject<{
6661
6715
  target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined;
6662
6716
  mode?: "none" | "development" | "production" | undefined;
6663
6717
  experiments?: {
6664
- lazyCompilation?: boolean | undefined;
6718
+ lazyCompilation?: boolean | {
6719
+ imports?: boolean | undefined;
6720
+ entries?: boolean | undefined;
6721
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
6722
+ } | undefined;
6665
6723
  asyncWebAssembly?: boolean | undefined;
6666
6724
  outputModule?: boolean | undefined;
6667
6725
  topLevelAwait?: boolean | undefined;
@@ -7085,7 +7143,11 @@ export declare const rspackOptions: z.ZodObject<{
7085
7143
  target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined;
7086
7144
  mode?: "none" | "development" | "production" | undefined;
7087
7145
  experiments?: {
7088
- lazyCompilation?: boolean | undefined;
7146
+ lazyCompilation?: boolean | {
7147
+ imports?: boolean | undefined;
7148
+ entries?: boolean | undefined;
7149
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
7150
+ } | undefined;
7089
7151
  asyncWebAssembly?: boolean | undefined;
7090
7152
  outputModule?: boolean | undefined;
7091
7153
  topLevelAwait?: boolean | undefined;
@@ -749,8 +749,16 @@ const rspackFutureOptions = zod_1.z.strictObject({
749
749
  })
750
750
  .optional()
751
751
  });
752
+ const lazyCompilationOptions = zod_1.z.object({
753
+ imports: zod_1.z.boolean().optional(),
754
+ entries: zod_1.z.boolean().optional(),
755
+ test: zod_1.z
756
+ .instanceof(RegExp)
757
+ .or(zod_1.z.function().args(zod_1.z.custom()).returns(zod_1.z.boolean()))
758
+ .optional()
759
+ });
752
760
  const experiments = zod_1.z.strictObject({
753
- lazyCompilation: zod_1.z.boolean().optional(),
761
+ lazyCompilation: zod_1.z.boolean().optional().or(lazyCompilationOptions),
754
762
  asyncWebAssembly: zod_1.z.boolean().optional(),
755
763
  outputModule: zod_1.z.boolean().optional(),
756
764
  topLevelAwait: zod_1.z.boolean().optional(),
@@ -14,6 +14,7 @@ exports.RspackOptionsApply = void 0;
14
14
  * https://github.com/webpack/webpack/blob/main/LICENSE
15
15
  */
16
16
  const assert_1 = __importDefault(require("assert"));
17
+ const Module_1 = require("./Module");
17
18
  const graceful_fs_1 = __importDefault(require("../compiled/graceful-fs"));
18
19
  const builtin_plugin_1 = require("./builtin-plugin");
19
20
  const EntryOptionPlugin_1 = __importDefault(require("./lib/EntryOptionPlugin"));
@@ -25,7 +26,7 @@ const cleverMerge_1 = require("./util/cleverMerge");
25
26
  class RspackOptionsApply {
26
27
  constructor() { }
27
28
  process(options, compiler) {
28
- var _a;
29
+ var _a, _b, _c, _d;
29
30
  (0, assert_1.default)(options.output.path, "options.output.path should have value after `applyRspackOptionsDefaults`");
30
31
  compiler.outputPath = options.output.path;
31
32
  compiler.name = options.name;
@@ -163,6 +164,24 @@ class RspackOptionsApply {
163
164
  new builtin_plugin_1.MangleExportsPlugin(options.optimization.mangleExports !== "size").apply(compiler);
164
165
  }
165
166
  }
167
+ if (options.experiments.lazyCompilation) {
168
+ const lazyOptions = options.experiments.lazyCompilation;
169
+ new builtin_plugin_1.LazyCompilationPlugin(
170
+ // this is only for test
171
+ // @ts-expect-error cacheable is hide
172
+ (_b = lazyOptions.cacheable) !== null && _b !== void 0 ? _b : true, (_c = lazyOptions.entries) !== null && _c !== void 0 ? _c : true, (_d = lazyOptions.imports) !== null && _d !== void 0 ? _d : true, typeof lazyOptions.test === "function"
173
+ ? function (jsModule) {
174
+ return lazyOptions.test.call(lazyOptions, new Module_1.Module(jsModule));
175
+ }
176
+ : lazyOptions.test
177
+ ? {
178
+ source: lazyOptions.test.source,
179
+ flags: lazyOptions.test.flags
180
+ }
181
+ : undefined,
182
+ // @ts-expect-error backend is hide
183
+ lazyOptions.backend).apply(compiler);
184
+ }
166
185
  if (options.output.enabledLibraryTypes &&
167
186
  options.output.enabledLibraryTypes.length > 0) {
168
187
  for (const type of options.output.enabledLibraryTypes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "0.6.5-canary-2456d69-20240515093621",
3
+ "version": "0.6.5-canary-5042eed-20240515115707",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "A Fast Rust-based Web Bundler",
@@ -71,8 +71,8 @@
71
71
  "watchpack": "^2.4.0",
72
72
  "zod": "^3.21.4",
73
73
  "zod-validation-error": "1.3.1",
74
- "@rspack/core": "0.6.5-canary-2456d69-20240515093621",
75
- "@rspack/plugin-minify": "^0.6.5-canary-2456d69-20240515093621"
74
+ "@rspack/plugin-minify": "^0.6.5-canary-5042eed-20240515115707",
75
+ "@rspack/core": "0.6.5-canary-5042eed-20240515115707"
76
76
  },
77
77
  "dependencies": {
78
78
  "@module-federation/runtime-tools": "0.1.6",
@@ -80,7 +80,7 @@
80
80
  "enhanced-resolve": "5.12.0",
81
81
  "tapable": "2.2.1",
82
82
  "webpack-sources": "3.2.3",
83
- "@rspack/binding": "0.6.5-canary-2456d69-20240515093621"
83
+ "@rspack/binding": "0.6.5-canary-5042eed-20240515115707"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@swc/helpers": ">=0.5.1"