@rsbuild/core 0.6.1 → 0.6.3
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 +1 -1
- package/dist/cli/prepare.js +1 -1
- package/dist/client/hmr.mjs +3 -0
- package/dist/config.js +2 -2
- package/dist/createRsbuild.js +2 -4
- package/dist/index.js +1 -1
- package/dist/initHooks.d.ts +6 -7
- package/dist/initHooks.js +6 -7
- package/dist/plugins/html.d.ts +2 -2
- package/dist/plugins/html.js +52 -13
- package/dist/plugins/index.d.ts +25 -2
- package/dist/plugins/index.js +2 -3
- package/dist/plugins/inlineChunk.js +1 -1
- package/dist/plugins/moment.js +2 -33
- package/dist/plugins/resourceHints.d.ts +2 -0
- package/dist/plugins/{preloadOrPrefetch.js → resourceHints.js} +33 -7
- package/dist/provider/createContext.js +1 -1
- package/dist/provider/devMiddleware.js +1 -5
- package/dist/provider/initPlugins.js +11 -7
- package/dist/provider/plugins/swc.js +1 -1
- package/dist/provider/provider.js +41 -4
- package/dist/provider/rspackConfig.js +2 -0
- package/dist/provider/shared.d.ts +1 -4
- package/dist/provider/shared.js +1 -50
- package/dist/rspack/HtmlAppIconPlugin.js +4 -5
- package/dist/rspack/HtmlBasicPlugin.d.ts +3 -2
- package/dist/rspack/HtmlBasicPlugin.js +29 -14
- package/package.json +3 -3
- package/dist/plugins/networkPerformance.d.ts +0 -2
- package/dist/plugins/networkPerformance.js +0 -59
- package/dist/plugins/preloadOrPrefetch.d.ts +0 -2
- package/dist/rspack/HtmlCrossOriginPlugin.d.ts +0 -12
- package/dist/rspack/HtmlCrossOriginPlugin.js +0 -66
- package/dist/rspack/HtmlNetworkPerformancePlugin.d.ts +0 -10
- package/dist/rspack/HtmlNetworkPerformancePlugin.js +0 -79
- package/dist/rspack/HtmlNoncePlugin.d.ts +0 -11
- package/dist/rspack/HtmlNoncePlugin.js +0 -67
package/dist/cli/commands.js
CHANGED
|
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
|
|
|
39
39
|
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");
|
|
40
40
|
};
|
|
41
41
|
function runCli() {
|
|
42
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.
|
|
42
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.6.3");
|
|
43
43
|
const devCommand = import_commander.program.command("dev");
|
|
44
44
|
const buildCommand = import_commander.program.command("build");
|
|
45
45
|
const previewCommand = import_commander.program.command("preview");
|
package/dist/cli/prepare.js
CHANGED
|
@@ -34,7 +34,7 @@ function prepareCli() {
|
|
|
34
34
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
|
|
35
35
|
console.log();
|
|
36
36
|
}
|
|
37
|
-
import_rslog.logger.greet(` ${`Rsbuild v${"0.6.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.6.3"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/client/hmr.mjs
CHANGED
|
@@ -367,6 +367,9 @@ function tryApplyUpdates() {
|
|
|
367
367
|
function handleApplyUpdates(err, updatedModules) {
|
|
368
368
|
var wantsForcedReload = err || !updatedModules;
|
|
369
369
|
if (wantsForcedReload) {
|
|
370
|
+
if (err && typeof console !== "undefined" && typeof console.error === "function") {
|
|
371
|
+
console.error("[HMR] Forced reload caused by: ", err);
|
|
372
|
+
}
|
|
370
373
|
window.location.reload();
|
|
371
374
|
return;
|
|
372
375
|
}
|
package/dist/config.js
CHANGED
|
@@ -160,8 +160,8 @@ function getDefaultEntry(root) {
|
|
|
160
160
|
"js",
|
|
161
161
|
"tsx",
|
|
162
162
|
"jsx",
|
|
163
|
-
"
|
|
164
|
-
"
|
|
163
|
+
"mjs",
|
|
164
|
+
"cjs"
|
|
165
165
|
].map((ext) => (0, import_node_path.join)(root, `src/index.${ext}`));
|
|
166
166
|
const entryFile = (0, import_shared.findExists)(files);
|
|
167
167
|
if (entryFile) {
|
package/dist/createRsbuild.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(createRsbuild_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(createRsbuild_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
var import_plugins = require("./plugins");
|
|
36
35
|
var import_pluginManager = require("./pluginManager");
|
|
37
36
|
const getRspackProvider = async () => {
|
|
38
37
|
const { rspackProvider } = await Promise.resolve().then(() => __toESM(require("./provider/provider")));
|
|
@@ -59,7 +58,6 @@ async function createRsbuild(options = {}) {
|
|
|
59
58
|
startDevServer,
|
|
60
59
|
applyDefaultPlugins
|
|
61
60
|
} = await provider({
|
|
62
|
-
plugins: import_plugins.plugins,
|
|
63
61
|
pluginManager,
|
|
64
62
|
rsbuildOptions
|
|
65
63
|
});
|
|
@@ -94,8 +92,8 @@ async function createRsbuild(options = {}) {
|
|
|
94
92
|
context: publicContext
|
|
95
93
|
};
|
|
96
94
|
if (rsbuildConfig.plugins) {
|
|
97
|
-
const
|
|
98
|
-
rsbuild.addPlugins(
|
|
95
|
+
const plugins = await Promise.all(rsbuildConfig.plugins);
|
|
96
|
+
rsbuild.addPlugins(plugins);
|
|
99
97
|
}
|
|
100
98
|
return rsbuild;
|
|
101
99
|
}
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ var import_config = require("./config");
|
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
39
|
var import_mergeConfig = require("./mergeConfig");
|
|
40
40
|
var import_constants = require("./constants");
|
|
41
|
-
const version = "0.6.
|
|
41
|
+
const version = "0.6.3";
|
|
42
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
43
|
0 && (module.exports = {
|
|
44
44
|
PLUGIN_CSS_NAME,
|
package/dist/initHooks.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import type { OnExitFn, AsyncHook, OnAfterBuildFn, OnBeforeBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, ModifyBundlerChainFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterStartProdServerFn, OnBeforeStartProdServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn } from '@rsbuild/shared';
|
|
1
|
+
import type { OnExitFn, AsyncHook, OnAfterBuildFn, OnBeforeBuildFn, ModifyHTMLTagsFn, OnCloseDevServerFn, OnDevCompileDoneFn, ModifyBundlerChainFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterStartProdServerFn, OnBeforeStartProdServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn } from '@rsbuild/shared';
|
|
2
2
|
export declare function createAsyncHook<Callback extends (...args: any[]) => any>(): AsyncHook<Callback>;
|
|
3
3
|
export declare function initHooks(): {
|
|
4
|
-
/** parameters are not bundler-related */
|
|
5
4
|
onExit: AsyncHook<OnExitFn>;
|
|
5
|
+
onAfterBuild: AsyncHook<OnAfterBuildFn>;
|
|
6
|
+
onBeforeBuild: AsyncHook<OnBeforeBuildFn>;
|
|
6
7
|
onDevCompileDone: AsyncHook<OnDevCompileDoneFn>;
|
|
7
8
|
onCloseDevServer: AsyncHook<OnCloseDevServerFn>;
|
|
8
9
|
onAfterStartDevServer: AsyncHook<OnAfterStartDevServerFn>;
|
|
9
10
|
onBeforeStartDevServer: AsyncHook<OnBeforeStartDevServerFn>;
|
|
10
11
|
onAfterStartProdServer: AsyncHook<OnAfterStartProdServerFn>;
|
|
11
12
|
onBeforeStartProdServer: AsyncHook<OnBeforeStartProdServerFn>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
onAfterCreateCompiler: AsyncHook<OnAfterCreateCompilerFn>;
|
|
14
|
+
onBeforeCreateCompiler: AsyncHook<OnBeforeCreateCompilerFn>;
|
|
15
|
+
modifyHTMLTags: AsyncHook<ModifyHTMLTagsFn>;
|
|
15
16
|
modifyRspackConfig: AsyncHook<ModifyRspackConfigFn>;
|
|
16
17
|
modifyBundlerChain: AsyncHook<ModifyBundlerChainFn>;
|
|
17
18
|
modifyWebpackChain: AsyncHook<ModifyWebpackChainFn>;
|
|
18
19
|
modifyWebpackConfig: AsyncHook<ModifyWebpackConfigFn>;
|
|
19
20
|
modifyRsbuildConfig: AsyncHook<ModifyRsbuildConfigFn>;
|
|
20
|
-
onAfterCreateCompiler: AsyncHook<OnAfterCreateCompilerFn>;
|
|
21
|
-
onBeforeCreateCompiler: AsyncHook<OnBeforeCreateCompilerFn>;
|
|
22
21
|
};
|
|
23
22
|
export type Hooks = ReturnType<typeof initHooks>;
|
package/dist/initHooks.js
CHANGED
|
@@ -56,24 +56,23 @@ function createAsyncHook() {
|
|
|
56
56
|
}
|
|
57
57
|
function initHooks() {
|
|
58
58
|
return {
|
|
59
|
-
/** parameters are not bundler-related */
|
|
60
59
|
onExit: createAsyncHook(),
|
|
60
|
+
onAfterBuild: createAsyncHook(),
|
|
61
|
+
onBeforeBuild: createAsyncHook(),
|
|
61
62
|
onDevCompileDone: createAsyncHook(),
|
|
62
63
|
onCloseDevServer: createAsyncHook(),
|
|
63
64
|
onAfterStartDevServer: createAsyncHook(),
|
|
64
65
|
onBeforeStartDevServer: createAsyncHook(),
|
|
65
66
|
onAfterStartProdServer: createAsyncHook(),
|
|
66
67
|
onBeforeStartProdServer: createAsyncHook(),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
onAfterCreateCompiler: createAsyncHook(),
|
|
69
|
+
onBeforeCreateCompiler: createAsyncHook(),
|
|
70
|
+
modifyHTMLTags: createAsyncHook(),
|
|
70
71
|
modifyRspackConfig: createAsyncHook(),
|
|
71
72
|
modifyBundlerChain: createAsyncHook(),
|
|
72
73
|
modifyWebpackChain: createAsyncHook(),
|
|
73
74
|
modifyWebpackConfig: createAsyncHook(),
|
|
74
|
-
modifyRsbuildConfig: createAsyncHook()
|
|
75
|
-
onAfterCreateCompiler: createAsyncHook(),
|
|
76
|
-
onBeforeCreateCompiler: createAsyncHook()
|
|
75
|
+
modifyRsbuildConfig: createAsyncHook()
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HtmlConfig, NormalizedConfig } from '@rsbuild/shared';
|
|
1
|
+
import type { HtmlConfig, NormalizedConfig, ModifyHTMLTagsFn } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildPlugin } from '../types';
|
|
3
3
|
export declare function getTitle(entryName: string, config: NormalizedConfig): string;
|
|
4
4
|
export declare function getInject(entryName: string, config: NormalizedConfig): import("@rsbuild/shared").ScriptInject;
|
|
@@ -12,4 +12,4 @@ export declare function getFavicon(entryName: string, config: {
|
|
|
12
12
|
export declare function getMetaTags(entryName: string, config: {
|
|
13
13
|
html: HtmlConfig;
|
|
14
14
|
}, templateContent?: string): import("@rsbuild/shared").MetaOptions;
|
|
15
|
-
export declare const pluginHtml: () => RsbuildPlugin;
|
|
15
|
+
export declare const pluginHtml: (modifyTagsFn: ModifyHTMLTagsFn) => RsbuildPlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -156,7 +156,7 @@ const getTagConfig = (api) => {
|
|
|
156
156
|
tags
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
const pluginHtml = () => ({
|
|
159
|
+
const pluginHtml = (modifyTagsFn) => ({
|
|
160
160
|
name: "rsbuild:html",
|
|
161
161
|
setup(api) {
|
|
162
162
|
api.modifyBundlerChain(
|
|
@@ -236,22 +236,11 @@ const pluginHtml = () => ({
|
|
|
236
236
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions[index]]);
|
|
237
237
|
});
|
|
238
238
|
const { HtmlBasicPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlBasicPlugin")));
|
|
239
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [htmlInfoMap]);
|
|
240
|
-
if (config.security) {
|
|
241
|
-
const { nonce } = config.security;
|
|
242
|
-
if (nonce) {
|
|
243
|
-
const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlNoncePlugin")));
|
|
244
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [{ nonce }]);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
239
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [htmlInfoMap, modifyTagsFn]);
|
|
247
240
|
if (config.html) {
|
|
248
241
|
const { appIcon, crossorigin } = config.html;
|
|
249
242
|
if (crossorigin) {
|
|
250
|
-
const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlCrossOriginPlugin")));
|
|
251
243
|
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
252
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
|
|
253
|
-
{ crossOrigin: formattedCrossorigin }
|
|
254
|
-
]);
|
|
255
244
|
chain.output.crossOriginLoading(formattedCrossorigin);
|
|
256
245
|
}
|
|
257
246
|
if (appIcon) {
|
|
@@ -263,6 +252,56 @@ const pluginHtml = () => ({
|
|
|
263
252
|
}
|
|
264
253
|
}
|
|
265
254
|
);
|
|
255
|
+
api.onAfterCreateCompiler(({ compiler }) => {
|
|
256
|
+
const { nonce } = api.getNormalizedConfig().security;
|
|
257
|
+
if (!nonce) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
(0, import_shared.applyToCompiler)(compiler, (compiler2) => {
|
|
261
|
+
const { plugins } = compiler2.options;
|
|
262
|
+
const hasHTML = plugins.some(
|
|
263
|
+
(plugin) => plugin && plugin.constructor.name === "HtmlBasicPlugin"
|
|
264
|
+
);
|
|
265
|
+
if (!hasHTML) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const injectCode = (0, import_shared.createVirtualModule)(
|
|
269
|
+
`__webpack_nonce__ = "${nonce}";`
|
|
270
|
+
);
|
|
271
|
+
new compiler2.webpack.EntryPlugin(compiler2.context, injectCode, {
|
|
272
|
+
name: void 0
|
|
273
|
+
}).apply(compiler2);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
api.modifyHTMLTags({
|
|
277
|
+
// ensure `crossorigin` and `nonce` can be applied to all tags
|
|
278
|
+
order: "post",
|
|
279
|
+
handler: ({ headTags, bodyTags }) => {
|
|
280
|
+
var _a;
|
|
281
|
+
const config = api.getNormalizedConfig();
|
|
282
|
+
const { crossorigin } = config.html;
|
|
283
|
+
const { nonce } = config.security;
|
|
284
|
+
const allTags = [...headTags, ...bodyTags];
|
|
285
|
+
if (crossorigin) {
|
|
286
|
+
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
287
|
+
for (const tag of allTags) {
|
|
288
|
+
if (tag.tag === "script" && tag.attrs?.src || tag.tag === "link" && tag.attrs?.rel === "stylesheet") {
|
|
289
|
+
tag.attrs || (tag.attrs = {});
|
|
290
|
+
(_a = tag.attrs).crossorigin ?? (_a.crossorigin = formattedCrossorigin);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (nonce) {
|
|
295
|
+
for (const tag of allTags) {
|
|
296
|
+
if (tag.tag === "script" || tag.tag === "style") {
|
|
297
|
+
tag.attrs ?? (tag.attrs = {});
|
|
298
|
+
tag.attrs.nonce = nonce;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return { headTags, bodyTags };
|
|
303
|
+
}
|
|
304
|
+
});
|
|
266
305
|
}
|
|
267
306
|
});
|
|
268
307
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const plugins:
|
|
1
|
+
import type { ModifyHTMLTagsFn } from '@rsbuild/shared';
|
|
2
|
+
export declare const plugins: {
|
|
3
|
+
basic: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
4
|
+
html: (modifyTagsFn: ModifyHTMLTagsFn) => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
5
|
+
cleanOutput: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
6
|
+
startUrl: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
7
|
+
fileSize: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
8
|
+
target: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
9
|
+
entry: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
10
|
+
cache: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
11
|
+
splitChunks: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
12
|
+
inlineChunk: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
13
|
+
bundleAnalyzer: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
14
|
+
rsdoctor: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
15
|
+
asset: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
16
|
+
wasm: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
17
|
+
moment: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
18
|
+
nodeAddons: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
19
|
+
externals: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
20
|
+
resourceHints: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
21
|
+
performance: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
22
|
+
define: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
23
|
+
server: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
24
|
+
moduleFederation: () => Promise<import("@rsbuild/shared").RsbuildPlugin>;
|
|
25
|
+
};
|
package/dist/plugins/index.js
CHANGED
|
@@ -33,7 +33,7 @@ __export(plugins_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(plugins_exports);
|
|
34
34
|
const plugins = {
|
|
35
35
|
basic: () => Promise.resolve().then(() => __toESM(require("./basic"))).then((m) => m.pluginBasic()),
|
|
36
|
-
html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml()),
|
|
36
|
+
html: (modifyTagsFn) => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml(modifyTagsFn)),
|
|
37
37
|
cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.pluginCleanOutput()),
|
|
38
38
|
startUrl: () => Promise.resolve().then(() => __toESM(require("./startUrl"))).then((m) => m.pluginStartUrl()),
|
|
39
39
|
fileSize: () => Promise.resolve().then(() => __toESM(require("./fileSize"))).then((m) => m.pluginFileSize()),
|
|
@@ -49,8 +49,7 @@ const plugins = {
|
|
|
49
49
|
moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
|
|
50
50
|
nodeAddons: () => Promise.resolve().then(() => __toESM(require("./nodeAddons"))).then((m) => m.pluginNodeAddons()),
|
|
51
51
|
externals: () => Promise.resolve().then(() => __toESM(require("./externals"))).then((m) => m.pluginExternals()),
|
|
52
|
-
|
|
53
|
-
preloadOrPrefetch: () => Promise.resolve().then(() => __toESM(require("./preloadOrPrefetch"))).then((m) => m.pluginPreloadOrPrefetch()),
|
|
52
|
+
resourceHints: () => Promise.resolve().then(() => __toESM(require("./resourceHints"))).then((m) => m.pluginResourceHints()),
|
|
54
53
|
performance: () => Promise.resolve().then(() => __toESM(require("./performance"))).then((m) => m.pluginPerformance()),
|
|
55
54
|
define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.pluginDefine()),
|
|
56
55
|
server: () => Promise.resolve().then(() => __toESM(require("./server"))).then((m) => m.pluginServer()),
|
|
@@ -53,7 +53,7 @@ const pluginInlineChunk = () => ({
|
|
|
53
53
|
if (!scriptTests.length && !styleTests.length) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).before(CHAIN_ID.PLUGIN.
|
|
56
|
+
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).before(CHAIN_ID.PLUGIN.HTML_BASIC).use(InlineChunkHtmlPlugin, [
|
|
57
57
|
{
|
|
58
58
|
styleTests,
|
|
59
59
|
scriptTests,
|
package/dist/plugins/moment.js
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,48 +16,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
19
|
var moment_exports = {};
|
|
25
20
|
__export(moment_exports, {
|
|
26
21
|
pluginMoment: () => pluginMoment
|
|
27
22
|
});
|
|
28
23
|
module.exports = __toCommonJS(moment_exports);
|
|
29
|
-
class IgnorePlugin {
|
|
30
|
-
constructor(options) {
|
|
31
|
-
__publicField(this, "options");
|
|
32
|
-
this.options = options;
|
|
33
|
-
this.checkIgnore = this.checkIgnore.bind(this);
|
|
34
|
-
}
|
|
35
|
-
checkIgnore(resolveData) {
|
|
36
|
-
if ("resourceRegExp" in this.options && this.options.resourceRegExp && this.options.resourceRegExp.test(resolveData.request)) {
|
|
37
|
-
if ("contextRegExp" in this.options && this.options.contextRegExp) {
|
|
38
|
-
if (this.options.contextRegExp.test(resolveData.context)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
apply(compiler) {
|
|
47
|
-
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", (nmf) => {
|
|
48
|
-
nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
|
49
|
-
});
|
|
50
|
-
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", (cmf) => {
|
|
51
|
-
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
24
|
const pluginMoment = () => ({
|
|
56
25
|
name: "rsbuild:moment",
|
|
57
26
|
setup(api) {
|
|
58
|
-
api.modifyBundlerChain(async (chain) => {
|
|
27
|
+
api.modifyBundlerChain(async (chain, { bundler }) => {
|
|
59
28
|
const config = api.getNormalizedConfig();
|
|
60
29
|
if (config.performance.removeMomentLocale) {
|
|
61
|
-
chain.plugin("remove-moment-locale").use(IgnorePlugin, [
|
|
30
|
+
chain.plugin("remove-moment-locale").use(bundler.IgnorePlugin, [
|
|
62
31
|
{
|
|
63
32
|
resourceRegExp: /^\.\/locale$/,
|
|
64
33
|
contextRegExp: /moment$/
|
|
@@ -26,14 +26,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var resourceHints_exports = {};
|
|
30
|
+
__export(resourceHints_exports, {
|
|
31
|
+
pluginResourceHints: () => pluginResourceHints
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
-
const
|
|
35
|
-
|
|
33
|
+
module.exports = __toCommonJS(resourceHints_exports);
|
|
34
|
+
const generateLinks = (options, rel) => options.map((option) => ({
|
|
35
|
+
tag: "link",
|
|
36
|
+
attrs: {
|
|
37
|
+
rel,
|
|
38
|
+
...option
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
const pluginResourceHints = () => ({
|
|
42
|
+
name: "rsbuild:resource-hints",
|
|
36
43
|
setup(api) {
|
|
44
|
+
api.modifyHTMLTags(({ headTags, bodyTags }) => {
|
|
45
|
+
const config = api.getNormalizedConfig();
|
|
46
|
+
const { dnsPrefetch, preconnect } = config.performance;
|
|
47
|
+
if (dnsPrefetch) {
|
|
48
|
+
const attrs = dnsPrefetch.map((option) => ({ href: option }));
|
|
49
|
+
if (attrs.length) {
|
|
50
|
+
headTags.unshift(...generateLinks(attrs, "dns-prefetch"));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (preconnect) {
|
|
54
|
+
const attrs = preconnect.map(
|
|
55
|
+
(option) => typeof option === "string" ? { href: option } : option
|
|
56
|
+
);
|
|
57
|
+
if (attrs.length) {
|
|
58
|
+
headTags.unshift(...generateLinks(attrs, "preconnect"));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { headTags, bodyTags };
|
|
62
|
+
});
|
|
37
63
|
api.modifyBundlerChain(
|
|
38
64
|
async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker }) => {
|
|
39
65
|
const config = api.getNormalizedConfig();
|
|
@@ -61,5 +87,5 @@ const pluginPreloadOrPrefetch = () => ({
|
|
|
61
87
|
});
|
|
62
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
89
|
0 && (module.exports = {
|
|
64
|
-
|
|
90
|
+
pluginResourceHints
|
|
65
91
|
});
|
|
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
|
|
|
44
44
|
const context = {
|
|
45
45
|
entry: (0, import_entry.getEntryObject)(config, "web"),
|
|
46
46
|
targets: config.output?.targets || [],
|
|
47
|
-
version: "0.6.
|
|
47
|
+
version: "0.6.3",
|
|
48
48
|
rootPath,
|
|
49
49
|
distPath,
|
|
50
50
|
cachePath,
|
|
@@ -62,11 +62,7 @@ const getDevMiddleware = (multiCompiler) => (options) => {
|
|
|
62
62
|
}
|
|
63
63
|
(0, import_shared.setupServerHooks)(compiler, callbacks);
|
|
64
64
|
};
|
|
65
|
-
|
|
66
|
-
multiCompiler.compilers.forEach(setupCompiler);
|
|
67
|
-
} else {
|
|
68
|
-
setupCompiler(multiCompiler);
|
|
69
|
-
}
|
|
65
|
+
(0, import_shared.applyToCompiler)(multiCompiler, setupCompiler);
|
|
70
66
|
return (0, import_webpack_dev_middleware.default)(multiCompiler, restOptions);
|
|
71
67
|
};
|
|
72
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -101,11 +101,14 @@ function getPluginAPI({
|
|
|
101
101
|
if (descriptor.test) {
|
|
102
102
|
rule.test(descriptor.test);
|
|
103
103
|
}
|
|
104
|
+
if (descriptor.resourceQuery) {
|
|
105
|
+
rule.resourceQuery(descriptor.resourceQuery);
|
|
106
|
+
}
|
|
104
107
|
rule.use(id).loader((0, import_node_path.join)(__dirname, "../rspack/transformLoader")).options({ id });
|
|
105
108
|
applyTransformPlugin(chain, transformer);
|
|
106
109
|
});
|
|
107
110
|
};
|
|
108
|
-
(
|
|
111
|
+
process.on("exit", () => {
|
|
109
112
|
hooks.onExit.call();
|
|
110
113
|
});
|
|
111
114
|
return {
|
|
@@ -123,17 +126,18 @@ function getPluginAPI({
|
|
|
123
126
|
onBeforeBuild: hooks.onBeforeBuild.tap,
|
|
124
127
|
onCloseDevServer: hooks.onCloseDevServer.tap,
|
|
125
128
|
onDevCompileDone: hooks.onDevCompileDone.tap,
|
|
126
|
-
modifyBundlerChain: hooks.modifyBundlerChain.tap,
|
|
127
|
-
modifyRspackConfig: hooks.modifyRspackConfig.tap,
|
|
128
|
-
modifyWebpackChain: hooks.modifyWebpackChain.tap,
|
|
129
|
-
modifyWebpackConfig: hooks.modifyWebpackConfig.tap,
|
|
130
|
-
modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap,
|
|
131
129
|
onAfterCreateCompiler: hooks.onAfterCreateCompiler.tap,
|
|
132
130
|
onAfterStartDevServer: hooks.onAfterStartDevServer.tap,
|
|
133
131
|
onBeforeCreateCompiler: hooks.onBeforeCreateCompiler.tap,
|
|
134
132
|
onBeforeStartDevServer: hooks.onBeforeStartDevServer.tap,
|
|
135
133
|
onAfterStartProdServer: hooks.onAfterStartProdServer.tap,
|
|
136
|
-
onBeforeStartProdServer: hooks.onBeforeStartProdServer.tap
|
|
134
|
+
onBeforeStartProdServer: hooks.onBeforeStartProdServer.tap,
|
|
135
|
+
modifyHTMLTags: hooks.modifyHTMLTags.tap,
|
|
136
|
+
modifyBundlerChain: hooks.modifyBundlerChain.tap,
|
|
137
|
+
modifyRspackConfig: hooks.modifyRspackConfig.tap,
|
|
138
|
+
modifyWebpackChain: hooks.modifyWebpackChain.tap,
|
|
139
|
+
modifyWebpackConfig: hooks.modifyWebpackConfig.tap,
|
|
140
|
+
modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap
|
|
137
141
|
};
|
|
138
142
|
}
|
|
139
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -87,7 +87,7 @@ const pluginSwc = () => ({
|
|
|
87
87
|
}
|
|
88
88
|
if ((0, import_shared.isWebTarget)(target)) {
|
|
89
89
|
const polyfillMode = config.output.polyfill;
|
|
90
|
-
if (polyfillMode === "off"
|
|
90
|
+
if (polyfillMode === "off") {
|
|
91
91
|
swcConfig.env.mode = void 0;
|
|
92
92
|
} else {
|
|
93
93
|
swcConfig.env.mode = polyfillMode;
|
|
@@ -35,11 +35,10 @@ var import_shared = require("@rsbuild/shared");
|
|
|
35
35
|
var import_createContext = require("./createContext");
|
|
36
36
|
var import_initConfigs = require("./initConfigs");
|
|
37
37
|
var import_initPlugins = require("./initPlugins");
|
|
38
|
-
var
|
|
38
|
+
var import_plugins = require("../plugins");
|
|
39
39
|
const rspackProvider = async ({
|
|
40
40
|
pluginManager,
|
|
41
|
-
rsbuildOptions
|
|
42
|
-
plugins
|
|
41
|
+
rsbuildOptions
|
|
43
42
|
}) => {
|
|
44
43
|
const rsbuildConfig = (0, import_shared.pickRsbuildConfig)(rsbuildOptions.rsbuildConfig);
|
|
45
44
|
const context = await (0, import_createContext.createContext)(rsbuildOptions, rsbuildConfig, "rspack");
|
|
@@ -63,7 +62,45 @@ const rspackProvider = async ({
|
|
|
63
62
|
createCompiler,
|
|
64
63
|
publicContext: (0, import_createContext.createPublicContext)(context),
|
|
65
64
|
async applyDefaultPlugins() {
|
|
66
|
-
|
|
65
|
+
const allPlugins = await Promise.all([
|
|
66
|
+
Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
|
|
67
|
+
import_plugins.plugins.basic(),
|
|
68
|
+
import_plugins.plugins.entry(),
|
|
69
|
+
// plugins.cache(),
|
|
70
|
+
import_plugins.plugins.target(),
|
|
71
|
+
Promise.resolve().then(() => __toESM(require("./plugins/output"))).then((m) => m.pluginOutput()),
|
|
72
|
+
Promise.resolve().then(() => __toESM(require("./plugins/resolve"))).then((m) => m.pluginResolve()),
|
|
73
|
+
import_plugins.plugins.fileSize(),
|
|
74
|
+
// cleanOutput plugin should before the html plugin
|
|
75
|
+
import_plugins.plugins.cleanOutput(),
|
|
76
|
+
import_plugins.plugins.asset(),
|
|
77
|
+
import_plugins.plugins.html(async (tags) => {
|
|
78
|
+
const result = await context.hooks.modifyHTMLTags.call(tags);
|
|
79
|
+
return result[0];
|
|
80
|
+
}),
|
|
81
|
+
import_plugins.plugins.wasm(),
|
|
82
|
+
import_plugins.plugins.moment(),
|
|
83
|
+
import_plugins.plugins.nodeAddons(),
|
|
84
|
+
import_plugins.plugins.define(),
|
|
85
|
+
Promise.resolve().then(() => __toESM(require("./plugins/css"))).then((m) => m.pluginCss()),
|
|
86
|
+
Promise.resolve().then(() => __toESM(require("./plugins/less"))).then((m) => m.pluginLess()),
|
|
87
|
+
Promise.resolve().then(() => __toESM(require("./plugins/sass"))).then((m) => m.pluginSass()),
|
|
88
|
+
Promise.resolve().then(() => __toESM(require("./plugins/minimize"))).then((m) => m.pluginMinimize()),
|
|
89
|
+
Promise.resolve().then(() => __toESM(require("./plugins/progress"))).then((m) => m.pluginProgress()),
|
|
90
|
+
Promise.resolve().then(() => __toESM(require("./plugins/swc"))).then((m) => m.pluginSwc()),
|
|
91
|
+
import_plugins.plugins.externals(),
|
|
92
|
+
import_plugins.plugins.splitChunks(),
|
|
93
|
+
import_plugins.plugins.startUrl(),
|
|
94
|
+
import_plugins.plugins.inlineChunk(),
|
|
95
|
+
import_plugins.plugins.bundleAnalyzer(),
|
|
96
|
+
import_plugins.plugins.rsdoctor(),
|
|
97
|
+
import_plugins.plugins.resourceHints(),
|
|
98
|
+
import_plugins.plugins.performance(),
|
|
99
|
+
import_plugins.plugins.server(),
|
|
100
|
+
import_plugins.plugins.moduleFederation(),
|
|
101
|
+
Promise.resolve().then(() => __toESM(require("./plugins/rspackProfile"))).then((m) => m.pluginRspackProfile())
|
|
102
|
+
]);
|
|
103
|
+
pluginManager.addPlugins(allPlugins);
|
|
67
104
|
},
|
|
68
105
|
async createDevServer(options) {
|
|
69
106
|
const { createDevServer } = await Promise.resolve().then(() => __toESM(require("../server/devServer")));
|
|
@@ -115,6 +115,7 @@ async function generateRspackConfig({
|
|
|
115
115
|
const {
|
|
116
116
|
BannerPlugin,
|
|
117
117
|
DefinePlugin,
|
|
118
|
+
IgnorePlugin,
|
|
118
119
|
ProvidePlugin,
|
|
119
120
|
HotModuleReplacementPlugin
|
|
120
121
|
} = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
@@ -123,6 +124,7 @@ async function generateRspackConfig({
|
|
|
123
124
|
bundler: {
|
|
124
125
|
BannerPlugin,
|
|
125
126
|
DefinePlugin,
|
|
127
|
+
IgnorePlugin,
|
|
126
128
|
ProvidePlugin,
|
|
127
129
|
HotModuleReplacementPlugin
|
|
128
130
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { isMultiCompiler, type Stats, type MultiStats, type StatsError } from '@rsbuild/shared';
|
|
2
|
-
import type { RsbuildPlugin } from '../types';
|
|
3
|
-
import { type Plugins } from '@rsbuild/shared';
|
|
4
2
|
import type { StatsCompilation, StatsValue } from '@rspack/core';
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const rspackMinVersion = "0.6.0";
|
|
3
|
+
export declare const rspackMinVersion = "0.6.2";
|
|
7
4
|
export declare const isSatisfyRspackVersion: (originalVersion: string) => Promise<boolean>;
|
|
8
5
|
export declare const getCompiledPath: (packageName: string) => string;
|
|
9
6
|
export declare const BUILTIN_LOADER = "builtin:";
|
package/dist/provider/shared.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,19 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var shared_exports = {};
|
|
30
20
|
__export(shared_exports, {
|
|
31
21
|
BUILTIN_LOADER: () => BUILTIN_LOADER,
|
|
32
|
-
applyDefaultPlugins: () => applyDefaultPlugins,
|
|
33
22
|
formatStats: () => formatStats,
|
|
34
23
|
getAllStatsErrors: () => getAllStatsErrors,
|
|
35
24
|
getAllStatsWarnings: () => getAllStatsWarnings,
|
|
@@ -42,45 +31,8 @@ module.exports = __toCommonJS(shared_exports);
|
|
|
42
31
|
var import_node_path = require("node:path");
|
|
43
32
|
var import_shared = require("@rsbuild/shared");
|
|
44
33
|
var import_shared2 = require("@rsbuild/shared");
|
|
45
|
-
var import_shared3 = require("@rsbuild/shared");
|
|
46
34
|
var import_formatStats = require("../client/formatStats");
|
|
47
|
-
const
|
|
48
|
-
Promise.resolve().then(() => __toESM(require("./plugins/transition"))).then((m) => m.pluginTransition()),
|
|
49
|
-
plugins.basic(),
|
|
50
|
-
plugins.entry(),
|
|
51
|
-
// plugins.cache(),
|
|
52
|
-
plugins.target(),
|
|
53
|
-
Promise.resolve().then(() => __toESM(require("./plugins/output"))).then((m) => m.pluginOutput()),
|
|
54
|
-
Promise.resolve().then(() => __toESM(require("./plugins/resolve"))).then((m) => m.pluginResolve()),
|
|
55
|
-
plugins.fileSize(),
|
|
56
|
-
// cleanOutput plugin should before the html plugin
|
|
57
|
-
plugins.cleanOutput(),
|
|
58
|
-
plugins.asset(),
|
|
59
|
-
plugins.html(),
|
|
60
|
-
plugins.wasm(),
|
|
61
|
-
plugins.moment(),
|
|
62
|
-
plugins.nodeAddons(),
|
|
63
|
-
plugins.define(),
|
|
64
|
-
Promise.resolve().then(() => __toESM(require("./plugins/css"))).then((m) => m.pluginCss()),
|
|
65
|
-
Promise.resolve().then(() => __toESM(require("./plugins/less"))).then((m) => m.pluginLess()),
|
|
66
|
-
Promise.resolve().then(() => __toESM(require("./plugins/sass"))).then((m) => m.pluginSass()),
|
|
67
|
-
Promise.resolve().then(() => __toESM(require("./plugins/minimize"))).then((m) => m.pluginMinimize()),
|
|
68
|
-
Promise.resolve().then(() => __toESM(require("./plugins/progress"))).then((m) => m.pluginProgress()),
|
|
69
|
-
Promise.resolve().then(() => __toESM(require("./plugins/swc"))).then((m) => m.pluginSwc()),
|
|
70
|
-
plugins.externals(),
|
|
71
|
-
plugins.splitChunks(),
|
|
72
|
-
plugins.startUrl(),
|
|
73
|
-
plugins.inlineChunk(),
|
|
74
|
-
plugins.bundleAnalyzer(),
|
|
75
|
-
plugins.rsdoctor(),
|
|
76
|
-
plugins.networkPerformance(),
|
|
77
|
-
plugins.preloadOrPrefetch(),
|
|
78
|
-
plugins.performance(),
|
|
79
|
-
plugins.server(),
|
|
80
|
-
plugins.moduleFederation(),
|
|
81
|
-
Promise.resolve().then(() => __toESM(require("./plugins/rspackProfile"))).then((m) => m.pluginRspackProfile())
|
|
82
|
-
]);
|
|
83
|
-
const rspackMinVersion = "0.6.0";
|
|
35
|
+
const rspackMinVersion = "0.6.2";
|
|
84
36
|
const compareSemver = (version1, version2) => {
|
|
85
37
|
const parts1 = version1.split(".").map(Number);
|
|
86
38
|
const parts2 = version2.split(".").map(Number);
|
|
@@ -253,7 +205,6 @@ function formatStats(stats, options = {}) {
|
|
|
253
205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
254
206
|
0 && (module.exports = {
|
|
255
207
|
BUILTIN_LOADER,
|
|
256
|
-
applyDefaultPlugins,
|
|
257
208
|
formatStats,
|
|
258
209
|
getAllStatsErrors,
|
|
259
210
|
getAllStatsWarnings,
|
|
@@ -38,7 +38,6 @@ __export(HtmlAppIconPlugin_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
|
|
39
39
|
var import_node_fs = __toESM(require("node:fs"));
|
|
40
40
|
var import_node_path = require("node:path");
|
|
41
|
-
var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
|
|
42
41
|
var import_shared = require("@rsbuild/shared");
|
|
43
42
|
var import_htmlUtils = require("../htmlUtils");
|
|
44
43
|
class HtmlAppIconPlugin {
|
|
@@ -81,11 +80,11 @@ class HtmlAppIconPlugin {
|
|
|
81
80
|
name: this.name,
|
|
82
81
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
83
82
|
},
|
|
84
|
-
(
|
|
83
|
+
() => {
|
|
85
84
|
const source = import_node_fs.default.readFileSync(this.iconPath);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
false
|
|
85
|
+
compilation.emitAsset(
|
|
86
|
+
iconRelativePath,
|
|
87
|
+
new compiler.webpack.sources.RawSource(source, false)
|
|
89
88
|
);
|
|
90
89
|
}
|
|
91
90
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
2
|
import type { HtmlTagObject } from 'html-webpack-plugin';
|
|
3
3
|
import type { Compiler } from '@rspack/core';
|
|
4
|
-
import { type HtmlTag, type HtmlTagDescriptor } from '@rsbuild/shared';
|
|
4
|
+
import { type HtmlTag, type HtmlTagDescriptor, type ModifyHTMLTagsFn } from '@rsbuild/shared';
|
|
5
5
|
export type TagConfig = {
|
|
6
6
|
tags?: HtmlTagDescriptor[];
|
|
7
7
|
hash?: HtmlTag['hash'];
|
|
@@ -33,6 +33,7 @@ export declare const hasTitle: (html?: string) => boolean;
|
|
|
33
33
|
export declare class HtmlBasicPlugin {
|
|
34
34
|
readonly name: string;
|
|
35
35
|
readonly options: HtmlBasicPluginOptions;
|
|
36
|
-
|
|
36
|
+
readonly modifyTagsFn: ModifyHTMLTagsFn;
|
|
37
|
+
constructor(options: HtmlBasicPluginOptions, modifyTagsFn: ModifyHTMLTagsFn);
|
|
37
38
|
apply(compiler: Compiler): void;
|
|
38
39
|
}
|
|
@@ -73,14 +73,24 @@ const getTagPriority = (tag, tagConfig) => {
|
|
|
73
73
|
}
|
|
74
74
|
return priority;
|
|
75
75
|
};
|
|
76
|
-
const
|
|
76
|
+
const formatBasicTag = (tag) => ({
|
|
77
77
|
tag: tag.tagName,
|
|
78
78
|
attrs: tag.attributes,
|
|
79
|
-
children: tag.innerHTML
|
|
79
|
+
children: tag.innerHTML
|
|
80
|
+
});
|
|
81
|
+
const fromBasicTag = (tag) => ({
|
|
82
|
+
meta: {},
|
|
83
|
+
tagName: tag.tag,
|
|
84
|
+
attributes: tag.attrs ?? {},
|
|
85
|
+
voidTag: VOID_TAGS.includes(tag.tag),
|
|
86
|
+
innerHTML: tag.children
|
|
87
|
+
});
|
|
88
|
+
const formatTags = (tags, override) => tags.map((tag) => ({
|
|
89
|
+
...formatBasicTag(tag),
|
|
80
90
|
publicPath: false,
|
|
81
91
|
...override
|
|
82
92
|
}));
|
|
83
|
-
const
|
|
93
|
+
const applyTagConfig = (data, tagConfig, compilationHash, entryName) => {
|
|
84
94
|
if (!tagConfig.tags?.length) {
|
|
85
95
|
return data;
|
|
86
96
|
}
|
|
@@ -114,14 +124,9 @@ const modifyTags = (data, tagConfig, compilationHash, entryName) => {
|
|
|
114
124
|
}
|
|
115
125
|
}
|
|
116
126
|
attrs[filenameTag] = filename;
|
|
127
|
+
tag.attrs = attrs;
|
|
117
128
|
}
|
|
118
|
-
ret.push(
|
|
119
|
-
meta: {},
|
|
120
|
-
tagName: tag.tag,
|
|
121
|
-
attributes: attrs,
|
|
122
|
-
voidTag: VOID_TAGS.includes(tag.tag),
|
|
123
|
-
innerHTML: tag.children
|
|
124
|
-
});
|
|
129
|
+
ret.push(fromBasicTag(tag));
|
|
125
130
|
}
|
|
126
131
|
return ret;
|
|
127
132
|
};
|
|
@@ -176,28 +181,38 @@ const addFavicon = (headTags, favicon) => {
|
|
|
176
181
|
}
|
|
177
182
|
};
|
|
178
183
|
class HtmlBasicPlugin {
|
|
179
|
-
constructor(options) {
|
|
184
|
+
constructor(options, modifyTagsFn) {
|
|
180
185
|
__publicField(this, "name");
|
|
181
186
|
__publicField(this, "options");
|
|
187
|
+
__publicField(this, "modifyTagsFn");
|
|
182
188
|
this.name = "HtmlBasicPlugin";
|
|
183
189
|
this.options = options;
|
|
190
|
+
this.modifyTagsFn = modifyTagsFn;
|
|
184
191
|
}
|
|
185
192
|
apply(compiler) {
|
|
186
193
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
187
|
-
(0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.
|
|
194
|
+
(0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.tapPromise(this.name, async (data) => {
|
|
188
195
|
const entryName = data.plugin.options?.entryName;
|
|
189
196
|
if (!entryName) {
|
|
190
197
|
return data;
|
|
191
198
|
}
|
|
192
|
-
const { headTags } = data;
|
|
199
|
+
const { headTags, bodyTags } = data;
|
|
193
200
|
const { favicon, tagConfig, templateContent } = this.options[entryName];
|
|
194
201
|
if (!hasTitle(templateContent)) {
|
|
195
202
|
addTitleTag(headTags, data.plugin.options?.title);
|
|
196
203
|
}
|
|
197
204
|
addFavicon(headTags, favicon);
|
|
205
|
+
const result = await this.modifyTagsFn({
|
|
206
|
+
headTags: headTags.map(formatBasicTag),
|
|
207
|
+
bodyTags: bodyTags.map(formatBasicTag)
|
|
208
|
+
});
|
|
209
|
+
Object.assign(data, {
|
|
210
|
+
headTags: result.headTags.map(fromBasicTag),
|
|
211
|
+
bodyTags: result.bodyTags.map(fromBasicTag)
|
|
212
|
+
});
|
|
198
213
|
if (tagConfig) {
|
|
199
214
|
const hash = compilation.hash ?? "";
|
|
200
|
-
|
|
215
|
+
applyTagConfig(data, tagConfig, hash, entryName);
|
|
201
216
|
}
|
|
202
217
|
return data;
|
|
203
218
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "The Rspack-based build tool.",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"types.d.ts"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@rspack/core": "0.6.
|
|
51
|
+
"@rspack/core": "0.6.2",
|
|
52
52
|
"@swc/helpers": "0.5.3",
|
|
53
53
|
"core-js": "~3.36.0",
|
|
54
54
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
|
|
55
55
|
"postcss": "^8.4.38",
|
|
56
|
-
"@rsbuild/shared": "0.6.
|
|
56
|
+
"@rsbuild/shared": "0.6.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "16.x",
|
|
@@ -1,59 +0,0 @@
|
|
|
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 __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var networkPerformance_exports = {};
|
|
30
|
-
__export(networkPerformance_exports, {
|
|
31
|
-
pluginNetworkPerformance: () => pluginNetworkPerformance
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(networkPerformance_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
const pluginNetworkPerformance = () => ({
|
|
36
|
-
name: "rsbuild:network-performance",
|
|
37
|
-
setup(api) {
|
|
38
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
39
|
-
const config = api.getNormalizedConfig();
|
|
40
|
-
const {
|
|
41
|
-
performance: { dnsPrefetch, preconnect }
|
|
42
|
-
} = config;
|
|
43
|
-
if ((0, import_shared.isHtmlDisabled)(config, target)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const { HtmlNetworkPerformancePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack/HtmlNetworkPerformancePlugin")));
|
|
47
|
-
if (dnsPrefetch) {
|
|
48
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(HtmlNetworkPerformancePlugin, [dnsPrefetch, "dnsPrefetch"]);
|
|
49
|
-
}
|
|
50
|
-
if (preconnect) {
|
|
51
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(HtmlNetworkPerformancePlugin, [preconnect, "preconnect"]);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
-
0 && (module.exports = {
|
|
58
|
-
pluginNetworkPerformance
|
|
59
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type CrossOrigin } from '@rsbuild/shared';
|
|
2
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
3
|
-
type CrossOriginOptions = {
|
|
4
|
-
crossOrigin: CrossOrigin;
|
|
5
|
-
};
|
|
6
|
-
export declare class HtmlCrossOriginPlugin implements RspackPluginInstance {
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly crossOrigin: CrossOrigin;
|
|
9
|
-
constructor(options: CrossOriginOptions);
|
|
10
|
-
apply(compiler: Compiler): void;
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var HtmlCrossOriginPlugin_exports = {};
|
|
25
|
-
__export(HtmlCrossOriginPlugin_exports, {
|
|
26
|
-
HtmlCrossOriginPlugin: () => HtmlCrossOriginPlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(HtmlCrossOriginPlugin_exports);
|
|
29
|
-
var import_shared = require("@rsbuild/shared");
|
|
30
|
-
var import_htmlUtils = require("../htmlUtils");
|
|
31
|
-
class HtmlCrossOriginPlugin {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
__publicField(this, "name");
|
|
34
|
-
__publicField(this, "crossOrigin");
|
|
35
|
-
const { crossOrigin } = options;
|
|
36
|
-
this.name = "HtmlCrossOriginPlugin";
|
|
37
|
-
this.crossOrigin = crossOrigin;
|
|
38
|
-
}
|
|
39
|
-
apply(compiler) {
|
|
40
|
-
if (!this.crossOrigin) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (this.crossOrigin !== "use-credentials") {
|
|
44
|
-
const { publicPath } = compiler.options.output;
|
|
45
|
-
if (!publicPath || publicPath === import_shared.DEFAULT_ASSET_PREFIX || publicPath === "auto") {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
50
|
-
(0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTags.tap(this.name, (alterAssetTags) => {
|
|
51
|
-
var _a;
|
|
52
|
-
const {
|
|
53
|
-
assetTags: { scripts, styles }
|
|
54
|
-
} = alterAssetTags;
|
|
55
|
-
for (const tag of [...scripts, ...styles]) {
|
|
56
|
-
(_a = tag.attributes).crossorigin ?? (_a.crossorigin = this.crossOrigin);
|
|
57
|
-
}
|
|
58
|
-
return alterAssetTags;
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
-
0 && (module.exports = {
|
|
65
|
-
HtmlCrossOriginPlugin
|
|
66
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import { type Preconnect, type DnsPrefetch } from '@rsbuild/shared';
|
|
3
|
-
type NetworkPerformanceType = 'preconnect' | 'dnsPrefetch';
|
|
4
|
-
export declare class HtmlNetworkPerformancePlugin implements RspackPluginInstance {
|
|
5
|
-
readonly options: DnsPrefetch | Preconnect;
|
|
6
|
-
readonly type: NetworkPerformanceType;
|
|
7
|
-
constructor(options: DnsPrefetch | Preconnect, type: NetworkPerformanceType);
|
|
8
|
-
apply(compiler: Compiler): void;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var HtmlNetworkPerformancePlugin_exports = {};
|
|
25
|
-
__export(HtmlNetworkPerformancePlugin_exports, {
|
|
26
|
-
HtmlNetworkPerformancePlugin: () => HtmlNetworkPerformancePlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(HtmlNetworkPerformancePlugin_exports);
|
|
29
|
-
var import_shared = require("@rsbuild/shared");
|
|
30
|
-
var import_htmlUtils = require("../htmlUtils");
|
|
31
|
-
function generateLinks(options, type) {
|
|
32
|
-
const relMap = {
|
|
33
|
-
preconnect: "preconnect",
|
|
34
|
-
dnsPrefetch: "dns-prefetch"
|
|
35
|
-
};
|
|
36
|
-
return options.map((option) => ({
|
|
37
|
-
tagName: "link",
|
|
38
|
-
attributes: {
|
|
39
|
-
rel: relMap[type],
|
|
40
|
-
...option
|
|
41
|
-
},
|
|
42
|
-
voidTag: false,
|
|
43
|
-
meta: {}
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
class HtmlNetworkPerformancePlugin {
|
|
47
|
-
constructor(options, type) {
|
|
48
|
-
__publicField(this, "options");
|
|
49
|
-
__publicField(this, "type");
|
|
50
|
-
this.options = options;
|
|
51
|
-
this.type = type;
|
|
52
|
-
}
|
|
53
|
-
apply(compiler) {
|
|
54
|
-
compiler.hooks.compilation.tap(
|
|
55
|
-
`HTML${this.type}Plugin`,
|
|
56
|
-
(compilation) => {
|
|
57
|
-
(0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.tap(
|
|
58
|
-
`HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
|
|
59
|
-
(htmlPluginData) => {
|
|
60
|
-
const { headTags } = htmlPluginData;
|
|
61
|
-
const options = this.options.map(
|
|
62
|
-
(option) => typeof option === "string" ? {
|
|
63
|
-
href: option
|
|
64
|
-
} : option
|
|
65
|
-
);
|
|
66
|
-
if (options.length) {
|
|
67
|
-
headTags.unshift(...generateLinks(options, this.type));
|
|
68
|
-
}
|
|
69
|
-
return htmlPluginData;
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
-
0 && (module.exports = {
|
|
78
|
-
HtmlNetworkPerformancePlugin
|
|
79
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
type NonceOptions = {
|
|
3
|
-
nonce: string;
|
|
4
|
-
};
|
|
5
|
-
export declare class HtmlNoncePlugin implements RspackPluginInstance {
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly nonce: string;
|
|
8
|
-
constructor(options: NonceOptions);
|
|
9
|
-
apply(compiler: Compiler): void;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var HtmlNoncePlugin_exports = {};
|
|
25
|
-
__export(HtmlNoncePlugin_exports, {
|
|
26
|
-
HtmlNoncePlugin: () => HtmlNoncePlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(HtmlNoncePlugin_exports);
|
|
29
|
-
var import_htmlUtils = require("../htmlUtils");
|
|
30
|
-
var import_shared = require("@rsbuild/shared");
|
|
31
|
-
class HtmlNoncePlugin {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
__publicField(this, "name");
|
|
34
|
-
__publicField(this, "nonce");
|
|
35
|
-
const { nonce } = options;
|
|
36
|
-
this.name = "HtmlNoncePlugin";
|
|
37
|
-
this.nonce = nonce;
|
|
38
|
-
}
|
|
39
|
-
apply(compiler) {
|
|
40
|
-
if (!this.nonce) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const injectCode = (0, import_shared.createVirtualModule)(
|
|
44
|
-
`__webpack_nonce__ = "${this.nonce}";`
|
|
45
|
-
);
|
|
46
|
-
new compiler.webpack.EntryPlugin(compiler.context, injectCode, {
|
|
47
|
-
name: void 0
|
|
48
|
-
}).apply(compiler);
|
|
49
|
-
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
50
|
-
(0, import_htmlUtils.getHTMLPlugin)().getHooks(compilation).alterAssetTagGroups.tap(this.name, (data) => {
|
|
51
|
-
const { headTags, bodyTags } = data;
|
|
52
|
-
const allTags = [...headTags, ...bodyTags];
|
|
53
|
-
for (const tag of allTags) {
|
|
54
|
-
if (tag.tagName === "script" || tag.tagName === "style") {
|
|
55
|
-
tag.attributes ?? (tag.attributes = {});
|
|
56
|
-
tag.attributes.nonce = this.nonce;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return data;
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
-
0 && (module.exports = {
|
|
66
|
-
HtmlNoncePlugin
|
|
67
|
-
});
|