@rspack/core 0.7.0-beta.0-canary-fb4c8bc-20240520042124 → 0.7.0-beta.1

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 {
@@ -35,6 +35,7 @@ export * from "./InferAsyncModulesPlugin";
35
35
  export * from "./JavascriptModulesPlugin";
36
36
  export * from "./JsLoaderRspackPlugin";
37
37
  export * from "./JsonModulesPlugin";
38
+ export * from "./lazy-compilation/plugin";
38
39
  export * from "./LimitChunkCountPlugin";
39
40
  export * from "./MangleExportsPlugin";
40
41
  export * from "./MergeDuplicateChunksPlugin";
@@ -53,6 +53,7 @@ __exportStar(require("./InferAsyncModulesPlugin"), exports);
53
53
  __exportStar(require("./JavascriptModulesPlugin"), exports);
54
54
  __exportStar(require("./JsLoaderRspackPlugin"), exports);
55
55
  __exportStar(require("./JsonModulesPlugin"), exports);
56
+ __exportStar(require("./lazy-compilation/plugin"), exports);
56
57
  __exportStar(require("./LimitChunkCountPlugin"), exports);
57
58
  __exportStar(require("./MangleExportsPlugin"), exports);
58
59
  __exportStar(require("./MergeDuplicateChunksPlugin"), exports);
@@ -0,0 +1,50 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ import type { IncomingMessage, ServerOptions as ServerOptionsImport, ServerResponse } from "http";
6
+ import type { ListenOptions, Server } from "net";
7
+ import type { SecureContextOptions, TlsOptions } from "tls";
8
+ import type { Compiler } from "../..";
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 { JsModule, RawRegexMatcher } from "@rspack/binding";
2
+ import type { Compiler } from "../..";
3
+ import { LazyCompilationDefaultBackendOptions } from "./backend";
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 backend_1 = __importStar(require("./backend"));
28
+ const lazyCompilation_1 = require("./lazyCompilation");
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, Environment, 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, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LazyCompilationOptions, 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";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
13
  export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
14
  export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
@@ -79,7 +79,7 @@ export interface ModuleOptionsNormalized {
79
79
  noParse?: NoParseOption;
80
80
  }
81
81
  export interface ExperimentsNormalized {
82
- lazyCompilation?: boolean;
82
+ lazyCompilation?: false | LazyCompilationOptions;
83
83
  asyncWebAssembly?: boolean;
84
84
  outputModule?: boolean;
85
85
  topLevelAwait?: boolean;
@@ -191,7 +191,8 @@ const getNormalizedRspackOptions = (config) => {
191
191
  performance: config.performance,
192
192
  plugins: nestedArray(config.plugins, p => [...p]),
193
193
  experiments: nestedConfig(config.experiments, experiments => ({
194
- ...experiments
194
+ ...experiments,
195
+ lazyCompilation: optionalNestedConfig(experiments.lazyCompilation, options => (options === true ? {} : options))
195
196
  })),
196
197
  watch: config.watch,
197
198
  watchOptions: cloneObject(config.watchOptions),
@@ -4607,8 +4607,34 @@ declare const rspackFutureOptions: z.ZodObject<{
4607
4607
  } | undefined;
4608
4608
  }>;
4609
4609
  export type RspackFutureOptions = z.infer<typeof rspackFutureOptions>;
4610
+ declare const lazyCompilationOptions: z.ZodObject<{
4611
+ imports: z.ZodOptional<z.ZodBoolean>;
4612
+ entries: z.ZodOptional<z.ZodBoolean>;
4613
+ 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>]>>;
4614
+ }, "strip", z.ZodTypeAny, {
4615
+ imports?: boolean | undefined;
4616
+ entries?: boolean | undefined;
4617
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4618
+ }, {
4619
+ imports?: boolean | undefined;
4620
+ entries?: boolean | undefined;
4621
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4622
+ }>;
4623
+ export type LazyCompilationOptions = z.infer<typeof lazyCompilationOptions>;
4610
4624
  declare const experiments: z.ZodObject<{
4611
- lazyCompilation: z.ZodOptional<z.ZodBoolean>;
4625
+ lazyCompilation: z.ZodUnion<[z.ZodOptional<z.ZodBoolean>, z.ZodObject<{
4626
+ imports: z.ZodOptional<z.ZodBoolean>;
4627
+ entries: z.ZodOptional<z.ZodBoolean>;
4628
+ 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>]>>;
4629
+ }, "strip", z.ZodTypeAny, {
4630
+ imports?: boolean | undefined;
4631
+ entries?: boolean | undefined;
4632
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4633
+ }, {
4634
+ imports?: boolean | undefined;
4635
+ entries?: boolean | undefined;
4636
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4637
+ }>]>;
4612
4638
  asyncWebAssembly: z.ZodOptional<z.ZodBoolean>;
4613
4639
  outputModule: z.ZodOptional<z.ZodBoolean>;
4614
4640
  topLevelAwait: z.ZodOptional<z.ZodBoolean>;
@@ -4640,7 +4666,11 @@ declare const experiments: z.ZodObject<{
4640
4666
  } | undefined;
4641
4667
  }>>;
4642
4668
  }, "strict", z.ZodTypeAny, {
4643
- lazyCompilation?: boolean | undefined;
4669
+ lazyCompilation?: boolean | {
4670
+ imports?: boolean | undefined;
4671
+ entries?: boolean | undefined;
4672
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4673
+ } | undefined;
4644
4674
  asyncWebAssembly?: boolean | undefined;
4645
4675
  outputModule?: boolean | undefined;
4646
4676
  topLevelAwait?: boolean | undefined;
@@ -4654,7 +4684,11 @@ declare const experiments: z.ZodObject<{
4654
4684
  } | undefined;
4655
4685
  } | undefined;
4656
4686
  }, {
4657
- lazyCompilation?: boolean | undefined;
4687
+ lazyCompilation?: boolean | {
4688
+ imports?: boolean | undefined;
4689
+ entries?: boolean | undefined;
4690
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
4691
+ } | undefined;
4658
4692
  asyncWebAssembly?: boolean | undefined;
4659
4693
  outputModule?: boolean | undefined;
4660
4694
  topLevelAwait?: boolean | undefined;
@@ -5366,7 +5400,19 @@ export declare const rspackOptions: z.ZodObject<{
5366
5400
  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">]>>;
5367
5401
  mode: z.ZodOptional<z.ZodEnum<["development", "production", "none"]>>;
5368
5402
  experiments: z.ZodOptional<z.ZodObject<{
5369
- lazyCompilation: z.ZodOptional<z.ZodBoolean>;
5403
+ lazyCompilation: z.ZodUnion<[z.ZodOptional<z.ZodBoolean>, z.ZodObject<{
5404
+ imports: z.ZodOptional<z.ZodBoolean>;
5405
+ entries: z.ZodOptional<z.ZodBoolean>;
5406
+ 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>]>>;
5407
+ }, "strip", z.ZodTypeAny, {
5408
+ imports?: boolean | undefined;
5409
+ entries?: boolean | undefined;
5410
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5411
+ }, {
5412
+ imports?: boolean | undefined;
5413
+ entries?: boolean | undefined;
5414
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5415
+ }>]>;
5370
5416
  asyncWebAssembly: z.ZodOptional<z.ZodBoolean>;
5371
5417
  outputModule: z.ZodOptional<z.ZodBoolean>;
5372
5418
  topLevelAwait: z.ZodOptional<z.ZodBoolean>;
@@ -5398,7 +5444,11 @@ export declare const rspackOptions: z.ZodObject<{
5398
5444
  } | undefined;
5399
5445
  }>>;
5400
5446
  }, "strict", z.ZodTypeAny, {
5401
- lazyCompilation?: boolean | undefined;
5447
+ lazyCompilation?: boolean | {
5448
+ imports?: boolean | undefined;
5449
+ entries?: boolean | undefined;
5450
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5451
+ } | undefined;
5402
5452
  asyncWebAssembly?: boolean | undefined;
5403
5453
  outputModule?: boolean | undefined;
5404
5454
  topLevelAwait?: boolean | undefined;
@@ -5412,7 +5462,11 @@ export declare const rspackOptions: z.ZodObject<{
5412
5462
  } | undefined;
5413
5463
  } | undefined;
5414
5464
  }, {
5415
- lazyCompilation?: boolean | undefined;
5465
+ lazyCompilation?: boolean | {
5466
+ imports?: boolean | undefined;
5467
+ entries?: boolean | undefined;
5468
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
5469
+ } | undefined;
5416
5470
  asyncWebAssembly?: boolean | undefined;
5417
5471
  outputModule?: boolean | undefined;
5418
5472
  topLevelAwait?: boolean | undefined;
@@ -6853,7 +6907,11 @@ export declare const rspackOptions: z.ZodObject<{
6853
6907
  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;
6854
6908
  mode?: "none" | "development" | "production" | undefined;
6855
6909
  experiments?: {
6856
- lazyCompilation?: boolean | undefined;
6910
+ lazyCompilation?: boolean | {
6911
+ imports?: boolean | undefined;
6912
+ entries?: boolean | undefined;
6913
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
6914
+ } | undefined;
6857
6915
  asyncWebAssembly?: boolean | undefined;
6858
6916
  outputModule?: boolean | undefined;
6859
6917
  topLevelAwait?: boolean | undefined;
@@ -7292,7 +7350,11 @@ export declare const rspackOptions: z.ZodObject<{
7292
7350
  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;
7293
7351
  mode?: "none" | "development" | "production" | undefined;
7294
7352
  experiments?: {
7295
- lazyCompilation?: boolean | undefined;
7353
+ lazyCompilation?: boolean | {
7354
+ imports?: boolean | undefined;
7355
+ entries?: boolean | undefined;
7356
+ test?: RegExp | ((args_0: Module, ...args_1: unknown[]) => boolean) | undefined;
7357
+ } | undefined;
7296
7358
  asyncWebAssembly?: boolean | undefined;
7297
7359
  outputModule?: boolean | undefined;
7298
7360
  topLevelAwait?: boolean | undefined;
@@ -765,8 +765,16 @@ const rspackFutureOptions = zod_1.z.strictObject({
765
765
  })
766
766
  .optional()
767
767
  });
768
+ const lazyCompilationOptions = zod_1.z.object({
769
+ imports: zod_1.z.boolean().optional(),
770
+ entries: zod_1.z.boolean().optional(),
771
+ test: zod_1.z
772
+ .instanceof(RegExp)
773
+ .or(zod_1.z.function().args(zod_1.z.custom()).returns(zod_1.z.boolean()))
774
+ .optional()
775
+ });
768
776
  const experiments = zod_1.z.strictObject({
769
- lazyCompilation: zod_1.z.boolean().optional(),
777
+ lazyCompilation: zod_1.z.boolean().optional().or(lazyCompilationOptions),
770
778
  asyncWebAssembly: zod_1.z.boolean().optional(),
771
779
  outputModule: zod_1.z.boolean().optional(),
772
780
  topLevelAwait: zod_1.z.boolean().optional(),
@@ -18,6 +18,7 @@ const graceful_fs_1 = __importDefault(require("../compiled/graceful-fs"));
18
18
  const builtin_plugin_1 = require("./builtin-plugin");
19
19
  const EntryOptionPlugin_1 = __importDefault(require("./lib/EntryOptionPlugin"));
20
20
  const ignoreWarningsPlugin_1 = __importDefault(require("./lib/ignoreWarningsPlugin"));
21
+ const Module_1 = require("./Module");
21
22
  const DefaultStatsFactoryPlugin_1 = require("./stats/DefaultStatsFactoryPlugin");
22
23
  const DefaultStatsPrinterPlugin_1 = require("./stats/DefaultStatsPrinterPlugin");
23
24
  const assertNotNil_1 = require("./util/assertNotNil");
@@ -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.7.0-beta.0-canary-fb4c8bc-20240520042124",
3
+ "version": "0.7.0-beta.1",
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/plugin-minify": "^0.7.0-beta.0-canary-fb4c8bc-20240520042124",
75
- "@rspack/core": "0.7.0-beta.0-canary-fb4c8bc-20240520042124"
74
+ "@rspack/core": "0.7.0-beta.1",
75
+ "@rspack/plugin-minify": "^0.7.0-beta.1"
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.7.0-beta.0-canary-fb4c8bc-20240520042124"
83
+ "@rspack/binding": "0.7.0-beta.1"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@swc/helpers": ">=0.5.1"