@rsbuild/core 0.3.11 → 0.4.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.
- package/dist/cli/commands.js +2 -2
- package/dist/cli/config.d.ts +1 -6
- package/dist/cli/config.js +20 -34
- package/dist/cli/prepare.js +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -3
- package/dist/createRsbuild.js +6 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -3
- package/dist/pluginManager.d.ts +7 -0
- package/dist/pluginManager.js +176 -0
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/moduleFederation.d.ts +2 -0
- package/dist/plugins/moduleFederation.js +123 -0
- package/dist/provider/config.d.ts +1 -1
- package/dist/provider/config.js +107 -8
- package/dist/provider/{core/createCompiler.d.ts → createCompiler.d.ts} +1 -1
- package/dist/provider/{core/createCompiler.js → createCompiler.js} +1 -1
- package/dist/provider/{core/createContext.d.ts → createContext.d.ts} +1 -1
- package/dist/provider/{core/createContext.js → createContext.js} +2 -2
- package/dist/provider/index.d.ts +6 -6
- package/dist/provider/index.js +11 -9
- package/dist/provider/initConfigs.d.ts +11 -0
- package/dist/provider/{core/initConfigs.js → initConfigs.js} +8 -7
- package/dist/provider/{core/initHooks.d.ts → initHooks.d.ts} +2 -1
- package/dist/provider/{core/initHooks.js → initHooks.js} +1 -0
- package/dist/provider/initPlugins.d.ts +7 -0
- package/dist/provider/{core/initPlugins.js → initPlugins.js} +3 -2
- package/dist/provider/{core/inspectConfig.d.ts → inspectConfig.d.ts} +1 -1
- package/dist/provider/{core/inspectConfig.js → inspectConfig.js} +3 -3
- package/dist/provider/plugins/css.js +0 -1
- package/dist/provider/plugins/less.js +2 -1
- package/dist/provider/plugins/swc.js +1 -1
- package/dist/provider/provider.js +20 -20
- package/dist/provider/{core/rspackConfig.d.ts → rspackConfig.d.ts} +1 -1
- package/dist/provider/{core/rspackConfig.js → rspackConfig.js} +2 -2
- package/dist/provider/shared.d.ts +1 -1
- package/dist/provider/shared.js +79 -14
- package/dist/server/devServer.js +1 -0
- package/dist/server/helper.d.ts +14 -0
- package/dist/server/helper.js +64 -1
- package/dist/server/proxy.js +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
- package/dist/provider/core/initConfigs.d.ts +0 -11
- package/dist/provider/core/initPlugins.d.ts +0 -7
- /package/dist/provider/{core/build.d.ts → build.d.ts} +0 -0
- /package/dist/provider/{core/build.js → build.js} +0 -0
- /package/dist/provider/{core/devMiddleware.d.ts → devMiddleware.d.ts} +0 -0
- /package/dist/provider/{core/devMiddleware.js → devMiddleware.js} +0 -0
package/dist/cli/commands.js
CHANGED
|
@@ -56,7 +56,7 @@ async function init({
|
|
|
56
56
|
if ((0, import_shared.isDev)()) {
|
|
57
57
|
(0, import_restart.onBeforeRestartServer)(envs.cleanup);
|
|
58
58
|
}
|
|
59
|
-
const { content: config, filePath: configFilePath } = await (0, import_config.
|
|
59
|
+
const { content: config, filePath: configFilePath } = await (0, import_config.loadConfig)({
|
|
60
60
|
cwd: root,
|
|
61
61
|
path: commonOpts.config,
|
|
62
62
|
envMode: commonOpts.envMode
|
|
@@ -112,7 +112,7 @@ const applyServerOptions = (command) => {
|
|
|
112
112
|
command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
|
|
113
113
|
};
|
|
114
114
|
function runCli() {
|
|
115
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.
|
|
115
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.4.1");
|
|
116
116
|
const devCommand = import_commander.program.command("dev");
|
|
117
117
|
const buildCommand = import_commander.program.command("build");
|
|
118
118
|
const previewCommand = import_commander.program.command("preview");
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -16,12 +16,7 @@ export declare function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfig
|
|
|
16
16
|
export declare function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
|
|
17
17
|
export declare function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
|
|
18
18
|
export declare function watchFiles(files: string[]): Promise<void>;
|
|
19
|
-
export declare function
|
|
20
|
-
export declare function loadConfig({ cwd, path, }: {
|
|
21
|
-
cwd: string;
|
|
22
|
-
path?: string;
|
|
23
|
-
}): Promise<RsbuildConfig>;
|
|
24
|
-
export declare function loadConfigV2({ cwd, path, envMode, }: {
|
|
19
|
+
export declare function loadConfig({ cwd, path, envMode, }: {
|
|
25
20
|
cwd: string;
|
|
26
21
|
path?: string;
|
|
27
22
|
envMode?: string;
|
package/dist/cli/config.js
CHANGED
|
@@ -30,8 +30,6 @@ var config_exports = {};
|
|
|
30
30
|
__export(config_exports, {
|
|
31
31
|
defineConfig: () => defineConfig,
|
|
32
32
|
loadConfig: () => loadConfig,
|
|
33
|
-
loadConfigByPath: () => loadConfigByPath,
|
|
34
|
-
loadConfigV2: () => loadConfigV2,
|
|
35
33
|
watchFiles: () => watchFiles
|
|
36
34
|
});
|
|
37
35
|
module.exports = __toCommonJS(config_exports);
|
|
@@ -90,7 +88,18 @@ async function watchFiles(files) {
|
|
|
90
88
|
watcher.on("change", callback);
|
|
91
89
|
watcher.on("unlink", callback);
|
|
92
90
|
}
|
|
93
|
-
async function
|
|
91
|
+
async function loadConfig({
|
|
92
|
+
cwd,
|
|
93
|
+
path,
|
|
94
|
+
envMode
|
|
95
|
+
}) {
|
|
96
|
+
const configFile = resolveConfigPath(cwd, path);
|
|
97
|
+
if (!configFile) {
|
|
98
|
+
return {
|
|
99
|
+
content: {},
|
|
100
|
+
filePath: configFile
|
|
101
|
+
};
|
|
102
|
+
}
|
|
94
103
|
try {
|
|
95
104
|
const { default: jiti } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/jiti")));
|
|
96
105
|
const loadConfig2 = jiti(__filename, {
|
|
@@ -111,7 +120,10 @@ async function loadConfigByPath(configFile, envMode) {
|
|
|
111
120
|
if (result === void 0) {
|
|
112
121
|
throw new Error("Rsbuild config function must return a config object.");
|
|
113
122
|
}
|
|
114
|
-
return
|
|
123
|
+
return {
|
|
124
|
+
content: result,
|
|
125
|
+
filePath: configFile
|
|
126
|
+
};
|
|
115
127
|
}
|
|
116
128
|
if (!(0, import_shared.isObject)(configExport)) {
|
|
117
129
|
throw new Error(
|
|
@@ -120,44 +132,18 @@ async function loadConfigByPath(configFile, envMode) {
|
|
|
120
132
|
)}`
|
|
121
133
|
);
|
|
122
134
|
}
|
|
123
|
-
return configExport;
|
|
124
|
-
} catch (err) {
|
|
125
|
-
import_shared.logger.error(`Failed to load file: ${import_shared.color.dim(configFile)}`);
|
|
126
|
-
throw err;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async function loadConfig({
|
|
130
|
-
cwd,
|
|
131
|
-
path
|
|
132
|
-
}) {
|
|
133
|
-
const configFile = resolveConfigPath(cwd, path);
|
|
134
|
-
if (!configFile) {
|
|
135
|
-
return {};
|
|
136
|
-
}
|
|
137
|
-
return loadConfigByPath(configFile);
|
|
138
|
-
}
|
|
139
|
-
async function loadConfigV2({
|
|
140
|
-
cwd,
|
|
141
|
-
path,
|
|
142
|
-
envMode
|
|
143
|
-
}) {
|
|
144
|
-
const configFile = resolveConfigPath(cwd, path);
|
|
145
|
-
if (!configFile) {
|
|
146
135
|
return {
|
|
147
|
-
content:
|
|
136
|
+
content: configExport,
|
|
148
137
|
filePath: configFile
|
|
149
138
|
};
|
|
139
|
+
} catch (err) {
|
|
140
|
+
import_shared.logger.error(`Failed to load file: ${import_shared.color.dim(configFile)}`);
|
|
141
|
+
throw err;
|
|
150
142
|
}
|
|
151
|
-
return {
|
|
152
|
-
content: await loadConfigByPath(configFile, envMode),
|
|
153
|
-
filePath: configFile
|
|
154
|
-
};
|
|
155
143
|
}
|
|
156
144
|
// Annotate the CommonJS export names for ESM import in node:
|
|
157
145
|
0 && (module.exports = {
|
|
158
146
|
defineConfig,
|
|
159
147
|
loadConfig,
|
|
160
|
-
loadConfigByPath,
|
|
161
|
-
loadConfigV2,
|
|
162
148
|
watchFiles
|
|
163
149
|
});
|
package/dist/cli/prepare.js
CHANGED
|
@@ -34,7 +34,7 @@ function prepareCli() {
|
|
|
34
34
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
|
|
35
35
|
console.log();
|
|
36
36
|
}
|
|
37
|
-
import_rslog.logger.greet(` ${`Rsbuild v${"0.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.4.1"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,5 +2,4 @@ export declare const PLUGIN_SWC_NAME = "rsbuild:swc";
|
|
|
2
2
|
export declare const PLUGIN_CSS_NAME = "rsbuild:css";
|
|
3
3
|
export declare const PLUGIN_LESS_NAME = "rsbuild:less";
|
|
4
4
|
export declare const PLUGIN_SASS_NAME = "rsbuild:sass";
|
|
5
|
-
export declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
|
|
6
5
|
export declare const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
|
package/dist/constants.js
CHANGED
|
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constants_exports = {};
|
|
20
20
|
__export(constants_exports, {
|
|
21
|
-
PLUGIN_BABEL_NAME: () => PLUGIN_BABEL_NAME,
|
|
22
21
|
PLUGIN_CSS_NAME: () => PLUGIN_CSS_NAME,
|
|
23
22
|
PLUGIN_LESS_NAME: () => PLUGIN_LESS_NAME,
|
|
24
23
|
PLUGIN_SASS_NAME: () => PLUGIN_SASS_NAME,
|
|
@@ -30,11 +29,9 @@ const PLUGIN_SWC_NAME = "rsbuild:swc";
|
|
|
30
29
|
const PLUGIN_CSS_NAME = "rsbuild:css";
|
|
31
30
|
const PLUGIN_LESS_NAME = "rsbuild:less";
|
|
32
31
|
const PLUGIN_SASS_NAME = "rsbuild:sass";
|
|
33
|
-
const PLUGIN_BABEL_NAME = "rsbuild:babel";
|
|
34
32
|
const PLUGIN_STYLUS_NAME = "rsbuild:stylus";
|
|
35
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
34
|
0 && (module.exports = {
|
|
37
|
-
PLUGIN_BABEL_NAME,
|
|
38
35
|
PLUGIN_CSS_NAME,
|
|
39
36
|
PLUGIN_LESS_NAME,
|
|
40
37
|
PLUGIN_SASS_NAME,
|
package/dist/createRsbuild.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(createRsbuild_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(createRsbuild_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
var import_plugins = require("./plugins");
|
|
36
|
+
var import_pluginManager = require("./pluginManager");
|
|
36
37
|
const getRspackProvider = async () => {
|
|
37
38
|
const { rspackProvider } = await Promise.resolve().then(() => __toESM(require("./provider")));
|
|
38
39
|
return rspackProvider;
|
|
@@ -45,7 +46,7 @@ async function createRsbuild(options) {
|
|
|
45
46
|
rsbuildConfig,
|
|
46
47
|
...options
|
|
47
48
|
};
|
|
48
|
-
const
|
|
49
|
+
const pluginManager = (0, import_pluginManager.createPluginManager)();
|
|
49
50
|
const {
|
|
50
51
|
build,
|
|
51
52
|
preview,
|
|
@@ -59,14 +60,14 @@ async function createRsbuild(options) {
|
|
|
59
60
|
applyDefaultPlugins
|
|
60
61
|
} = await provider({
|
|
61
62
|
plugins: import_plugins.plugins,
|
|
62
|
-
|
|
63
|
+
pluginManager,
|
|
63
64
|
rsbuildOptions
|
|
64
65
|
});
|
|
65
66
|
(0, import_shared.debug)("add default plugins");
|
|
66
|
-
await applyDefaultPlugins(
|
|
67
|
+
await applyDefaultPlugins(pluginManager);
|
|
67
68
|
(0, import_shared.debug)("add default plugins done");
|
|
68
69
|
const rsbuild = {
|
|
69
|
-
...(0, import_shared.pick)(
|
|
70
|
+
...(0, import_shared.pick)(pluginManager, ["addPlugins", "removePlugins", "isPluginExists"]),
|
|
70
71
|
...(0, import_shared.pick)(pluginAPI, [
|
|
71
72
|
"onBeforeBuild",
|
|
72
73
|
"onBeforeCreateCompiler",
|
|
@@ -76,6 +77,7 @@ async function createRsbuild(options) {
|
|
|
76
77
|
"onAfterCreateCompiler",
|
|
77
78
|
"onAfterStartDevServer",
|
|
78
79
|
"onAfterStartProdServer",
|
|
80
|
+
"onCloseDevServer",
|
|
79
81
|
"onDevCompileDone",
|
|
80
82
|
"onExit",
|
|
81
83
|
"getHTMLPaths",
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { createRsbuild } from './createRsbuild';
|
|
|
7
7
|
export { loadConfig, defineConfig } from './cli/config';
|
|
8
8
|
export declare const version: any;
|
|
9
9
|
export { logger, mergeRsbuildConfig } from '@rsbuild/shared';
|
|
10
|
-
export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_SASS_NAME, PLUGIN_LESS_NAME,
|
|
10
|
+
export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME, PLUGIN_SASS_NAME, PLUGIN_LESS_NAME, PLUGIN_STYLUS_NAME, } from './constants';
|
|
11
11
|
export type { Rspack } from './provider';
|
|
12
12
|
export type { RsbuildConfig, DevConfig, HtmlConfig, ToolsConfig, SourceConfig, OutputConfig, SecurityConfig, PerformanceConfig, NormalizedConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedToolsConfig, NormalizedSourceConfig, NormalizedOutputConfig, NormalizedSecurityConfig, NormalizedPerformanceConfig, RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI, } from './types';
|
|
13
|
-
export type { RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildContext, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, } from '@rsbuild/shared';
|
|
13
|
+
export type { RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildContext, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnBeforeCreateCompilerFn, OnCloseDevServerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, } from '@rsbuild/shared';
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
|
-
PLUGIN_BABEL_NAME: () => import_constants.PLUGIN_BABEL_NAME,
|
|
22
21
|
PLUGIN_CSS_NAME: () => import_constants.PLUGIN_CSS_NAME,
|
|
23
22
|
PLUGIN_LESS_NAME: () => import_constants.PLUGIN_LESS_NAME,
|
|
24
23
|
PLUGIN_SASS_NAME: () => import_constants.PLUGIN_SASS_NAME,
|
|
@@ -38,10 +37,9 @@ var import_createRsbuild = require("./createRsbuild");
|
|
|
38
37
|
var import_config = require("./cli/config");
|
|
39
38
|
var import_shared = require("@rsbuild/shared");
|
|
40
39
|
var import_constants = require("./constants");
|
|
41
|
-
const version = "0.
|
|
40
|
+
const version = "0.4.1";
|
|
42
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
42
|
0 && (module.exports = {
|
|
44
|
-
PLUGIN_BABEL_NAME,
|
|
45
43
|
PLUGIN_CSS_NAME,
|
|
46
44
|
PLUGIN_LESS_NAME,
|
|
47
45
|
PLUGIN_SASS_NAME,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginManager, RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/shared';
|
|
2
|
+
export declare function createPluginManager(): PluginManager;
|
|
3
|
+
export declare const pluginDagSort: (plugins: RsbuildPlugin[]) => RsbuildPlugin[];
|
|
4
|
+
export declare function initPlugins({ pluginAPI, pluginManager, }: {
|
|
5
|
+
pluginAPI?: RsbuildPluginAPI;
|
|
6
|
+
pluginManager: PluginManager;
|
|
7
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var pluginManager_exports = {};
|
|
20
|
+
__export(pluginManager_exports, {
|
|
21
|
+
createPluginManager: () => createPluginManager,
|
|
22
|
+
initPlugins: () => initPlugins,
|
|
23
|
+
pluginDagSort: () => pluginDagSort
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(pluginManager_exports);
|
|
26
|
+
var import_shared = require("@rsbuild/shared");
|
|
27
|
+
function validatePlugin(plugin) {
|
|
28
|
+
const type = typeof plugin;
|
|
29
|
+
if (type !== "object" || plugin === null) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Expect Rsbuild plugin instance to be an object, but got ${type}.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if ((0, import_shared.isFunction)(plugin.setup)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if ((0, import_shared.isFunction)(plugin.apply)) {
|
|
38
|
+
const { name = "SomeWebpackPlugin" } = plugin.constructor || {};
|
|
39
|
+
const messages = [
|
|
40
|
+
`${import_shared.color.yellow(
|
|
41
|
+
name
|
|
42
|
+
)} looks like a Webpack or Rspack plugin, please use ${import_shared.color.yellow(
|
|
43
|
+
"`tools.rspack`"
|
|
44
|
+
)} to register it:`,
|
|
45
|
+
import_shared.color.green(`
|
|
46
|
+
// rsbuild.config.ts
|
|
47
|
+
export default {
|
|
48
|
+
tools: {
|
|
49
|
+
rspack: {
|
|
50
|
+
plugins: [new ${name}()]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
`)
|
|
55
|
+
];
|
|
56
|
+
throw new Error(messages.join("\n"));
|
|
57
|
+
}
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Expect Rsbuild plugin.setup to be a function, but got ${type}.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function createPluginManager() {
|
|
63
|
+
let plugins = [];
|
|
64
|
+
const addPlugins = (newPlugins, options) => {
|
|
65
|
+
const { before } = options || {};
|
|
66
|
+
newPlugins.forEach((newPlugin) => {
|
|
67
|
+
if (!newPlugin) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
validatePlugin(newPlugin);
|
|
71
|
+
if (plugins.find((item) => item.name === newPlugin.name)) {
|
|
72
|
+
import_shared.logger.warn(
|
|
73
|
+
`Rsbuild plugin "${newPlugin.name}" registered multiple times.`
|
|
74
|
+
);
|
|
75
|
+
} else if (before) {
|
|
76
|
+
const index = plugins.findIndex((item) => item.name === before);
|
|
77
|
+
if (index === -1) {
|
|
78
|
+
import_shared.logger.warn(`Plugin "${before}" does not exist.`);
|
|
79
|
+
plugins.push(newPlugin);
|
|
80
|
+
} else {
|
|
81
|
+
plugins.splice(index, 0, newPlugin);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
plugins.push(newPlugin);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const removePlugins = (pluginNames) => {
|
|
89
|
+
plugins = plugins.filter((plugin) => !pluginNames.includes(plugin.name));
|
|
90
|
+
};
|
|
91
|
+
const isPluginExists = (pluginName) => Boolean(plugins.find((plugin) => plugin.name === pluginName));
|
|
92
|
+
return {
|
|
93
|
+
get plugins() {
|
|
94
|
+
return plugins;
|
|
95
|
+
},
|
|
96
|
+
addPlugins,
|
|
97
|
+
removePlugins,
|
|
98
|
+
isPluginExists
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const pluginDagSort = (plugins) => {
|
|
102
|
+
let allLines = [];
|
|
103
|
+
function getPlugin(name) {
|
|
104
|
+
const target = plugins.find((item) => item.name === name);
|
|
105
|
+
if (!target) {
|
|
106
|
+
throw new Error(`plugin ${name} not existed`);
|
|
107
|
+
}
|
|
108
|
+
return target;
|
|
109
|
+
}
|
|
110
|
+
plugins.forEach((plugin) => {
|
|
111
|
+
plugin.pre?.forEach((pre) => {
|
|
112
|
+
if (pre && plugins.some((item) => item.name === pre)) {
|
|
113
|
+
allLines.push([pre, plugin.name]);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
plugin.post?.forEach((post) => {
|
|
117
|
+
if (post && plugins.some((item) => item.name === post)) {
|
|
118
|
+
allLines.push([plugin.name, post]);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
let zeroEndPoints = plugins.filter(
|
|
123
|
+
(item) => !allLines.find((l) => l[1] === item.name)
|
|
124
|
+
);
|
|
125
|
+
const sortedPoint = [];
|
|
126
|
+
while (zeroEndPoints.length) {
|
|
127
|
+
const zep = zeroEndPoints.shift();
|
|
128
|
+
sortedPoint.push(getPlugin(zep.name));
|
|
129
|
+
allLines = allLines.filter((l) => l[0] !== getPlugin(zep.name).name);
|
|
130
|
+
const restPoints = plugins.filter(
|
|
131
|
+
(item) => !sortedPoint.find((sp) => sp.name === item.name)
|
|
132
|
+
);
|
|
133
|
+
zeroEndPoints = restPoints.filter(
|
|
134
|
+
(item) => !allLines.find((l) => l[1] === item.name)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (allLines.length) {
|
|
138
|
+
const restInRingPoints = {};
|
|
139
|
+
allLines.forEach((l) => {
|
|
140
|
+
restInRingPoints[l[0]] = true;
|
|
141
|
+
restInRingPoints[l[1]] = true;
|
|
142
|
+
});
|
|
143
|
+
throw new Error(
|
|
144
|
+
`plugins dependencies has loop: ${Object.keys(restInRingPoints).join(
|
|
145
|
+
","
|
|
146
|
+
)}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return sortedPoint;
|
|
150
|
+
};
|
|
151
|
+
async function initPlugins({
|
|
152
|
+
pluginAPI,
|
|
153
|
+
pluginManager
|
|
154
|
+
}) {
|
|
155
|
+
(0, import_shared.debug)("init plugins");
|
|
156
|
+
const plugins = pluginDagSort(pluginManager.plugins);
|
|
157
|
+
const removedPlugins = plugins.reduce((ret, plugin) => {
|
|
158
|
+
if (plugin.remove) {
|
|
159
|
+
return ret.concat(plugin.remove);
|
|
160
|
+
}
|
|
161
|
+
return ret;
|
|
162
|
+
}, []);
|
|
163
|
+
for (const plugin of plugins) {
|
|
164
|
+
if (removedPlugins.includes(plugin.name)) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
await plugin.setup(pluginAPI);
|
|
168
|
+
}
|
|
169
|
+
(0, import_shared.debug)("init plugins done");
|
|
170
|
+
}
|
|
171
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
+
0 && (module.exports = {
|
|
173
|
+
createPluginManager,
|
|
174
|
+
initPlugins,
|
|
175
|
+
pluginDagSort
|
|
176
|
+
});
|
package/dist/plugins/index.js
CHANGED
|
@@ -53,7 +53,8 @@ const plugins = {
|
|
|
53
53
|
preloadOrPrefetch: () => Promise.resolve().then(() => __toESM(require("./preloadOrPrefetch"))).then((m) => m.pluginPreloadOrPrefetch()),
|
|
54
54
|
performance: () => Promise.resolve().then(() => __toESM(require("./performance"))).then((m) => m.pluginPerformance()),
|
|
55
55
|
define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.pluginDefine()),
|
|
56
|
-
server: () => Promise.resolve().then(() => __toESM(require("./server"))).then((m) => m.pluginServer())
|
|
56
|
+
server: () => Promise.resolve().then(() => __toESM(require("./server"))).then((m) => m.pluginServer()),
|
|
57
|
+
moduleFederation: () => Promise.resolve().then(() => __toESM(require("./moduleFederation"))).then((m) => m.pluginModuleFederation())
|
|
57
58
|
};
|
|
58
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
60
|
0 && (module.exports = {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var moduleFederation_exports = {};
|
|
35
|
+
__export(moduleFederation_exports, {
|
|
36
|
+
pluginModuleFederation: () => pluginModuleFederation
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(moduleFederation_exports);
|
|
39
|
+
var import_shared = require("@rsbuild/shared");
|
|
40
|
+
class PatchSplitChunksPlugin {
|
|
41
|
+
constructor(name) {
|
|
42
|
+
__publicField(this, "name");
|
|
43
|
+
this.name = name;
|
|
44
|
+
}
|
|
45
|
+
apply(compiler) {
|
|
46
|
+
const { splitChunks } = compiler.options.optimization;
|
|
47
|
+
if (!splitChunks) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const applyPatch = (cacheGroup) => {
|
|
51
|
+
if (typeof cacheGroup !== "object" || cacheGroup instanceof RegExp) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const { chunks } = cacheGroup;
|
|
55
|
+
if (!chunks) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (typeof chunks === "function") {
|
|
59
|
+
const prevChunks = chunks;
|
|
60
|
+
cacheGroup.chunks = (chunk) => {
|
|
61
|
+
if (chunk.name && chunk.name === this.name) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return prevChunks(chunk);
|
|
65
|
+
};
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (chunks === "all") {
|
|
69
|
+
cacheGroup.chunks = (chunk) => {
|
|
70
|
+
if (chunk.name && chunk.name === this.name) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (chunks === "initial") {
|
|
78
|
+
cacheGroup.chunks = (chunk) => {
|
|
79
|
+
if (chunk.name && chunk.name === this.name) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return chunk.isOnlyInitial();
|
|
83
|
+
};
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
applyPatch(splitChunks);
|
|
88
|
+
const { cacheGroups } = splitChunks;
|
|
89
|
+
if (!cacheGroups) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
Object.keys(cacheGroups).forEach((cacheGroupKey) => {
|
|
93
|
+
applyPatch(cacheGroups[cacheGroupKey]);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function pluginModuleFederation() {
|
|
98
|
+
return {
|
|
99
|
+
name: "rsbuild:module-federation",
|
|
100
|
+
setup(api) {
|
|
101
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
102
|
+
const config = api.getNormalizedConfig();
|
|
103
|
+
if (!config.moduleFederation?.options || target !== "web") {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const { options } = config.moduleFederation;
|
|
107
|
+
const { rspack } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
108
|
+
chain.plugin(CHAIN_ID.PLUGIN.MODULE_FEDERATION).use(rspack.container.ModuleFederationPlugin, [options]);
|
|
109
|
+
if (options.name) {
|
|
110
|
+
chain.plugin("mf-patch-split-chunks").use(PatchSplitChunksPlugin, [options.name]);
|
|
111
|
+
}
|
|
112
|
+
const publicPath = chain.output.get("publicPath");
|
|
113
|
+
if (publicPath === import_shared.DEFAULT_ASSET_PREFIX) {
|
|
114
|
+
chain.output.set("publicPath", "auto");
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
pluginModuleFederation
|
|
123
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RsbuildConfig, NormalizedConfig } from '@rsbuild/shared';
|
|
2
2
|
export declare const withDefaultConfig: (rootPath: string, config: RsbuildConfig) => Promise<RsbuildConfig>;
|
|
3
3
|
/** #__PURE__
|
|
4
4
|
* 1. May used by multiple plugins.
|