@rsbuild/core 0.1.4 → 0.1.5
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 +10 -3
- package/dist/cli/config.d.ts +1 -1
- package/dist/cli/config.js +13 -9
- package/dist/cli/prepare.js +1 -1
- package/dist/loadEnv.d.ts +8 -2
- package/dist/loadEnv.js +22 -10
- package/dist/plugins/html.js +6 -6
- package/dist/plugins/inlineChunk.js +1 -1
- package/dist/plugins/networkPerformance.js +13 -3
- package/dist/plugins/preloadOrPrefetch.js +13 -3
- package/dist/rspack-plugins/HtmlAppIconPlugin.d.ts +16 -0
- package/dist/rspack-plugins/HtmlAppIconPlugin.js +97 -0
- package/dist/rspack-plugins/HtmlCrossOriginPlugin.d.ts +15 -0
- package/dist/rspack-plugins/HtmlCrossOriginPlugin.js +59 -0
- package/dist/rspack-plugins/HtmlNetworkPerformancePlugin.d.ts +12 -0
- package/dist/rspack-plugins/HtmlNetworkPerformancePlugin.js +72 -0
- package/dist/rspack-plugins/HtmlNoncePlugin.d.ts +14 -0
- package/dist/rspack-plugins/HtmlNoncePlugin.js +52 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/determineAsValue.d.ts +25 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/determineAsValue.js +99 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/doesChunkBelongToHtml.d.ts +31 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/doesChunkBelongToHtml.js +75 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/extractChunks.d.ts +28 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/extractChunks.js +83 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/index.d.ts +4 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/index.js +28 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/type.d.ts +13 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/helpers/type.js +16 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/index.d.ts +30 -0
- package/dist/rspack-plugins/HtmlPreloadOrPrefetchPlugin/index.js +167 -0
- package/dist/rspack-plugins/HtmlTagsPlugin.d.ts +30 -0
- package/dist/rspack-plugins/HtmlTagsPlugin.js +173 -0
- package/dist/rspack-plugins/InlineChunkHtmlPlugin.d.ts +57 -0
- package/dist/rspack-plugins/InlineChunkHtmlPlugin.js +182 -0
- package/dist/rspack-provider/core/createContext.js +7 -3
- package/package.json +5 -4
package/dist/cli/commands.js
CHANGED
|
@@ -46,9 +46,15 @@ async function init({
|
|
|
46
46
|
commonOpts = cliOptions;
|
|
47
47
|
}
|
|
48
48
|
try {
|
|
49
|
-
|
|
50
|
-
const
|
|
49
|
+
const root = process.cwd();
|
|
50
|
+
const { publicVars } = await (0, import_loadEnv.loadEnv)({ dir: root });
|
|
51
|
+
const config = await (0, import_config.loadConfig)(root, commonOpts.config);
|
|
51
52
|
const { createRsbuild } = await Promise.resolve().then(() => __toESM(require("../createRsbuild")));
|
|
53
|
+
config.source || (config.source = {});
|
|
54
|
+
config.source.define = {
|
|
55
|
+
...publicVars,
|
|
56
|
+
...config.source.define
|
|
57
|
+
};
|
|
52
58
|
if (commonOpts.open && !config.dev?.startUrl) {
|
|
53
59
|
config.dev || (config.dev = {});
|
|
54
60
|
config.dev.startUrl = true;
|
|
@@ -62,6 +68,7 @@ async function init({
|
|
|
62
68
|
config.server.port = commonOpts.port;
|
|
63
69
|
}
|
|
64
70
|
return await createRsbuild({
|
|
71
|
+
cwd: root,
|
|
65
72
|
rsbuildConfig: config,
|
|
66
73
|
provider: config.provider
|
|
67
74
|
});
|
|
@@ -74,7 +81,7 @@ async function init({
|
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
function runCli() {
|
|
77
|
-
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.1.
|
|
84
|
+
import_commander.program.name("rsbuild").usage("<command> [options]").version("0.1.5");
|
|
78
85
|
import_commander.program.command("dev").option("--open", "open the page in browser on startup").option(
|
|
79
86
|
"--port <port>",
|
|
80
87
|
"specify a port number for Rsbuild Server to listen"
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export type RsbuildConfigExport = RsbuildConfig | RsbuildConfigFn;
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function defineConfig(config: RsbuildConfig): RsbuildConfig;
|
|
19
19
|
export declare function defineConfig(config: RsbuildConfigFn): RsbuildConfigFn;
|
|
20
|
-
export declare function loadConfig(customConfig?: string): Promise<RsbuildConfig>;
|
|
20
|
+
export declare function loadConfig(root: string, customConfig?: string): Promise<RsbuildConfig>;
|
package/dist/cli/config.js
CHANGED
|
@@ -35,12 +35,12 @@ module.exports = __toCommonJS(config_exports);
|
|
|
35
35
|
var import_fs = __toESM(require("fs"));
|
|
36
36
|
var import_path = require("path");
|
|
37
37
|
var import_shared = require("@rsbuild/shared");
|
|
38
|
+
var import_loadEnv = require("../loadEnv");
|
|
38
39
|
var import_restart = require("../server/restart");
|
|
39
40
|
function defineConfig(config) {
|
|
40
41
|
return config;
|
|
41
42
|
}
|
|
42
|
-
const resolveConfigPath = (customConfig) => {
|
|
43
|
-
const root = process.cwd();
|
|
43
|
+
const resolveConfigPath = (root, customConfig) => {
|
|
44
44
|
if (customConfig) {
|
|
45
45
|
const customConfigPath = (0, import_path.isAbsolute)(customConfig) ? customConfig : (0, import_path.join)(root, customConfig);
|
|
46
46
|
if (import_fs.default.existsSync(customConfigPath)) {
|
|
@@ -65,25 +65,29 @@ const resolveConfigPath = (customConfig) => {
|
|
|
65
65
|
}
|
|
66
66
|
return null;
|
|
67
67
|
};
|
|
68
|
-
async function watchConfig(configFile) {
|
|
68
|
+
async function watchConfig(root, configFile) {
|
|
69
69
|
const chokidar = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/chokidar")));
|
|
70
|
-
const
|
|
70
|
+
const envFiles = (0, import_loadEnv.getEnvFiles)().map((filename) => (0, import_path.join)(root, filename));
|
|
71
|
+
const watcher = chokidar.watch([configFile, ...envFiles], {
|
|
72
|
+
// do not trigger add for initial files
|
|
73
|
+
ignoreInitial: true,
|
|
71
74
|
// If watching fails due to read permissions, the errors will be suppressed silently.
|
|
72
75
|
ignorePermissionErrors: true
|
|
73
76
|
});
|
|
74
77
|
const callback = (0, import_shared.debounce)(
|
|
75
|
-
async () => {
|
|
78
|
+
async (filePath) => {
|
|
76
79
|
watcher.close();
|
|
77
|
-
await (0, import_restart.restartDevServer)({ filePath
|
|
80
|
+
await (0, import_restart.restartDevServer)({ filePath });
|
|
78
81
|
},
|
|
79
82
|
// set 300ms debounce to avoid restart frequently
|
|
80
83
|
300
|
|
81
84
|
);
|
|
85
|
+
watcher.on("add", callback);
|
|
82
86
|
watcher.on("change", callback);
|
|
83
87
|
watcher.on("unlink", callback);
|
|
84
88
|
}
|
|
85
|
-
async function loadConfig(customConfig) {
|
|
86
|
-
const configFile = resolveConfigPath(customConfig);
|
|
89
|
+
async function loadConfig(root, customConfig) {
|
|
90
|
+
const configFile = resolveConfigPath(root, customConfig);
|
|
87
91
|
if (!configFile) {
|
|
88
92
|
return {};
|
|
89
93
|
}
|
|
@@ -97,7 +101,7 @@ async function loadConfig(customConfig) {
|
|
|
97
101
|
});
|
|
98
102
|
const command = process.argv[2];
|
|
99
103
|
if (command === "dev") {
|
|
100
|
-
watchConfig(configFile);
|
|
104
|
+
watchConfig(root, configFile);
|
|
101
105
|
}
|
|
102
106
|
const configExport = loadConfig2(configFile);
|
|
103
107
|
if (typeof configExport === "function") {
|
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.1.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.1.5"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/loadEnv.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
export declare const getEnvFiles: () => string[];
|
|
1
2
|
export declare function loadEnv({
|
|
2
|
-
dir
|
|
3
|
+
dir,
|
|
4
|
+
prefixes
|
|
3
5
|
}?: {
|
|
4
6
|
dir?: string;
|
|
5
|
-
|
|
7
|
+
prefixes?: string[];
|
|
8
|
+
}): Promise<{
|
|
9
|
+
parsed: Record<string, string>;
|
|
10
|
+
publicVars: Record<string, string>;
|
|
11
|
+
}>;
|
package/dist/loadEnv.js
CHANGED
|
@@ -28,31 +28,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var loadEnv_exports = {};
|
|
30
30
|
__export(loadEnv_exports, {
|
|
31
|
+
getEnvFiles: () => getEnvFiles,
|
|
31
32
|
loadEnv: () => loadEnv
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(loadEnv_exports);
|
|
34
35
|
var import_fs = __toESM(require("fs"));
|
|
35
36
|
var import_path = require("path");
|
|
36
37
|
var import_shared = require("@rsbuild/shared");
|
|
37
|
-
|
|
38
|
+
const getEnvFiles = () => {
|
|
39
|
+
const { NODE_ENV } = process.env;
|
|
40
|
+
return [".env", ".env.local", `.env.${NODE_ENV}`, `.env.${NODE_ENV}.local`];
|
|
41
|
+
};
|
|
42
|
+
async function loadEnv({
|
|
43
|
+
dir = process.cwd(),
|
|
44
|
+
prefixes = ["PUBLIC_"]
|
|
45
|
+
} = {}) {
|
|
38
46
|
const { parse } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv")));
|
|
39
47
|
const { expand } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv-expand")));
|
|
40
|
-
const
|
|
41
|
-
const files = [
|
|
42
|
-
".env",
|
|
43
|
-
".env.local",
|
|
44
|
-
`.env.${NODE_ENV}`,
|
|
45
|
-
`.env.${NODE_ENV}.local`
|
|
46
|
-
];
|
|
47
|
-
const envPaths = files.map((filename) => (0, import_path.join)(dir, filename)).filter(import_shared.isFileSync);
|
|
48
|
+
const envPaths = getEnvFiles().map((filename) => (0, import_path.join)(dir, filename)).filter(import_shared.isFileSync);
|
|
48
49
|
const parsed = {};
|
|
49
50
|
envPaths.forEach((envPath) => {
|
|
50
51
|
Object.assign(parsed, parse(import_fs.default.readFileSync(envPath)));
|
|
51
52
|
});
|
|
52
53
|
expand({ parsed });
|
|
53
|
-
|
|
54
|
+
const publicVars = {};
|
|
55
|
+
Object.keys(process.env).forEach((key) => {
|
|
56
|
+
const val = process.env[key];
|
|
57
|
+
if (val && prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
58
|
+
publicVars[`process.env.${key}`] = JSON.stringify(val);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
parsed,
|
|
63
|
+
publicVars
|
|
64
|
+
};
|
|
54
65
|
}
|
|
55
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
67
|
0 && (module.exports = {
|
|
68
|
+
getEnvFiles,
|
|
57
69
|
loadEnv
|
|
58
70
|
});
|
package/dist/plugins/html.js
CHANGED
|
@@ -39,7 +39,6 @@ __export(html_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(html_exports);
|
|
40
40
|
var import_path = __toESM(require("path"));
|
|
41
41
|
var import_shared = require("@rsbuild/shared");
|
|
42
|
-
var import_HtmlBasicPlugin = require("../rspack-plugins/HtmlBasicPlugin");
|
|
43
42
|
function getTitle(entryName, config) {
|
|
44
43
|
return (0, import_shared.mergeChainedOptions)({
|
|
45
44
|
defaults: "",
|
|
@@ -156,7 +155,7 @@ const applyInjectTags = (api) => {
|
|
|
156
155
|
if (!tags.length && !shouldByEntries) {
|
|
157
156
|
return;
|
|
158
157
|
}
|
|
159
|
-
const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("
|
|
158
|
+
const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlTagsPlugin")));
|
|
160
159
|
const sharedOptions = {
|
|
161
160
|
HtmlPlugin,
|
|
162
161
|
append: true,
|
|
@@ -247,18 +246,19 @@ const pluginHtml = () => ({
|
|
|
247
246
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
|
|
248
247
|
})
|
|
249
248
|
);
|
|
250
|
-
|
|
249
|
+
const { HtmlBasicPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlBasicPlugin")));
|
|
250
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_BASIC).use(HtmlBasicPlugin, [{ HtmlPlugin, info: htmlInfoMap }]);
|
|
251
251
|
if (config.security) {
|
|
252
252
|
const { nonce } = config.security;
|
|
253
253
|
if (nonce) {
|
|
254
|
-
const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("
|
|
254
|
+
const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlNoncePlugin")));
|
|
255
255
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [{ nonce, HtmlPlugin }]);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (config.html) {
|
|
259
259
|
const { appIcon, crossorigin } = config.html;
|
|
260
260
|
if (crossorigin) {
|
|
261
|
-
const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("
|
|
261
|
+
const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlCrossOriginPlugin")));
|
|
262
262
|
const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
|
|
263
263
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
|
|
264
264
|
{ crossOrigin: formattedCrossorigin, HtmlPlugin }
|
|
@@ -266,7 +266,7 @@ const pluginHtml = () => ({
|
|
|
266
266
|
chain.output.crossOriginLoading(formattedCrossorigin);
|
|
267
267
|
}
|
|
268
268
|
if (appIcon) {
|
|
269
|
-
const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("
|
|
269
|
+
const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlAppIconPlugin")));
|
|
270
270
|
const distDir = (0, import_shared.getDistPath)(config.output, "image");
|
|
271
271
|
const iconPath = import_path.default.isAbsolute(appIcon) ? appIcon : import_path.default.join(api.context.rootPath, appIcon);
|
|
272
272
|
chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [{ iconPath, distDir, HtmlPlugin }]);
|
|
@@ -41,7 +41,7 @@ const pluginInlineChunk = () => ({
|
|
|
41
41
|
if ((0, import_shared.isHtmlDisabled)(config, target) || !isProd) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("
|
|
44
|
+
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/InlineChunkHtmlPlugin")));
|
|
45
45
|
const { inlineStyles, inlineScripts } = config.output;
|
|
46
46
|
const scriptTests = [];
|
|
47
47
|
const styleTests = [];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,13 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var networkPerformance_exports = {};
|
|
20
30
|
__export(networkPerformance_exports, {
|
|
21
31
|
pluginNetworkPerformance: () => pluginNetworkPerformance
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(networkPerformance_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
34
|
const pluginNetworkPerformance = () => ({
|
|
26
35
|
name: `plugin-network-performance`,
|
|
27
36
|
setup(api) {
|
|
@@ -34,15 +43,16 @@ const pluginNetworkPerformance = () => ({
|
|
|
34
43
|
if (isServer || isWebWorker || isServiceWorker) {
|
|
35
44
|
return;
|
|
36
45
|
}
|
|
46
|
+
const { HtmlNetworkPerformancePlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlNetworkPerformancePlugin")));
|
|
37
47
|
if (dnsPrefetch) {
|
|
38
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(
|
|
48
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(HtmlNetworkPerformancePlugin, [
|
|
39
49
|
dnsPrefetch,
|
|
40
50
|
"dnsPrefetch",
|
|
41
51
|
HtmlPlugin
|
|
42
52
|
]);
|
|
43
53
|
}
|
|
44
54
|
if (preconnect) {
|
|
45
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(
|
|
55
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(HtmlNetworkPerformancePlugin, [
|
|
46
56
|
preconnect,
|
|
47
57
|
"preconnect",
|
|
48
58
|
HtmlPlugin
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,13 +17,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var preloadOrPrefetch_exports = {};
|
|
20
30
|
__export(preloadOrPrefetch_exports, {
|
|
21
31
|
pluginPreloadOrPrefetch: () => pluginPreloadOrPrefetch
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(preloadOrPrefetch_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
34
|
const pluginPreloadOrPrefetch = () => ({
|
|
26
35
|
name: `plugin-preload-or-prefetch`,
|
|
27
36
|
setup(api) {
|
|
@@ -35,8 +44,9 @@ const pluginPreloadOrPrefetch = () => ({
|
|
|
35
44
|
return;
|
|
36
45
|
}
|
|
37
46
|
const HTMLCount = chain.entryPoints.values().length;
|
|
47
|
+
const { HTMLPreloadOrPrefetchPlugin } = await Promise.resolve().then(() => __toESM(require("../rspack-plugins/HtmlPreloadOrPrefetchPlugin")));
|
|
38
48
|
if (prefetch) {
|
|
39
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(
|
|
49
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH).use(HTMLPreloadOrPrefetchPlugin, [
|
|
40
50
|
prefetch,
|
|
41
51
|
"prefetch",
|
|
42
52
|
HtmlPlugin,
|
|
@@ -44,7 +54,7 @@ const pluginPreloadOrPrefetch = () => ({
|
|
|
44
54
|
]);
|
|
45
55
|
}
|
|
46
56
|
if (preload) {
|
|
47
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(
|
|
57
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD).use(HTMLPreloadOrPrefetchPlugin, [
|
|
48
58
|
preload,
|
|
49
59
|
"preload",
|
|
50
60
|
HtmlPlugin,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
import type { Compiler } from '@rspack/core';
|
|
3
|
+
type AppIconOptions = {
|
|
4
|
+
distDir: string;
|
|
5
|
+
iconPath: string;
|
|
6
|
+
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
7
|
+
};
|
|
8
|
+
export declare class HtmlAppIconPlugin {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly distDir: string;
|
|
11
|
+
readonly iconPath: string;
|
|
12
|
+
readonly HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
13
|
+
constructor(options: AppIconOptions);
|
|
14
|
+
apply(compiler: Compiler): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
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 HtmlAppIconPlugin_exports = {};
|
|
30
|
+
__export(HtmlAppIconPlugin_exports, {
|
|
31
|
+
HtmlAppIconPlugin: () => HtmlAppIconPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(HtmlAppIconPlugin_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_webpack_sources = __toESM(require("@rsbuild/shared/webpack-sources"));
|
|
37
|
+
var import_shared = require("@rsbuild/shared");
|
|
38
|
+
class HtmlAppIconPlugin {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.name = "HtmlAppIconPlugin";
|
|
41
|
+
this.distDir = options.distDir;
|
|
42
|
+
this.iconPath = options.iconPath;
|
|
43
|
+
this.HtmlPlugin = options.HtmlPlugin;
|
|
44
|
+
}
|
|
45
|
+
apply(compiler) {
|
|
46
|
+
if (!import_fs.default.existsSync(this.iconPath)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`[${this.name}] Can not find the app icon, please check if the '${this.iconPath}' file exists'.`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const iconRelativePath = import_path.default.join(
|
|
52
|
+
this.distDir,
|
|
53
|
+
import_path.default.basename(this.iconPath)
|
|
54
|
+
);
|
|
55
|
+
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
56
|
+
this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
|
|
57
|
+
this.name,
|
|
58
|
+
(data) => {
|
|
59
|
+
const { publicPath } = compiler.options.output;
|
|
60
|
+
data.headTags.unshift({
|
|
61
|
+
tagName: "link",
|
|
62
|
+
voidTag: true,
|
|
63
|
+
attributes: {
|
|
64
|
+
rel: "apple-touch-icon",
|
|
65
|
+
sizes: "180*180",
|
|
66
|
+
href: `${publicPath}${iconRelativePath}`
|
|
67
|
+
},
|
|
68
|
+
meta: {}
|
|
69
|
+
});
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
compiler.hooks.thisCompilation.tap(
|
|
75
|
+
this.name,
|
|
76
|
+
(compilation) => {
|
|
77
|
+
compilation.hooks.processAssets.tap(
|
|
78
|
+
{
|
|
79
|
+
name: this.name,
|
|
80
|
+
stage: import_shared.COMPILATION_PROCESS_STAGE.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
81
|
+
},
|
|
82
|
+
(assets) => {
|
|
83
|
+
const source = import_fs.default.readFileSync(this.iconPath);
|
|
84
|
+
assets[iconRelativePath] = new import_webpack_sources.default.RawSource(
|
|
85
|
+
source,
|
|
86
|
+
false
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
HtmlAppIconPlugin
|
|
97
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
import type { CrossOrigin } from '@rsbuild/shared';
|
|
3
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
4
|
+
type CrossOriginOptions = {
|
|
5
|
+
crossOrigin: CrossOrigin;
|
|
6
|
+
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
7
|
+
};
|
|
8
|
+
export declare class HtmlCrossOriginPlugin implements RspackPluginInstance {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly crossOrigin: CrossOrigin;
|
|
11
|
+
readonly HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
12
|
+
constructor(options: CrossOriginOptions);
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 HtmlCrossOriginPlugin_exports = {};
|
|
20
|
+
__export(HtmlCrossOriginPlugin_exports, {
|
|
21
|
+
HtmlCrossOriginPlugin: () => HtmlCrossOriginPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(HtmlCrossOriginPlugin_exports);
|
|
24
|
+
class HtmlCrossOriginPlugin {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
const { crossOrigin } = options;
|
|
27
|
+
this.name = "HtmlCrossOriginPlugin";
|
|
28
|
+
this.crossOrigin = crossOrigin;
|
|
29
|
+
this.HtmlPlugin = options.HtmlPlugin;
|
|
30
|
+
}
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
if (!this.crossOrigin || // align with crossOriginLoading logic
|
|
33
|
+
// https://github.com/web-infra-dev/rspack/blob/bc8e67b5419adda15c2b389517c9b37d02c8240f/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs#L39
|
|
34
|
+
compiler.options.output.publicPath === "/" && this.crossOrigin !== "use-credentials") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
38
|
+
this.HtmlPlugin.getHooks(compilation).alterAssetTags.tap(
|
|
39
|
+
this.name,
|
|
40
|
+
(alterAssetTags) => {
|
|
41
|
+
const {
|
|
42
|
+
assetTags: { scripts, styles }
|
|
43
|
+
} = alterAssetTags;
|
|
44
|
+
scripts.forEach(
|
|
45
|
+
(script) => script.attributes.crossorigin = this.crossOrigin
|
|
46
|
+
);
|
|
47
|
+
styles.forEach(
|
|
48
|
+
(style) => style.attributes.crossorigin = this.crossOrigin
|
|
49
|
+
);
|
|
50
|
+
return alterAssetTags;
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
HtmlCrossOriginPlugin
|
|
59
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
+
import { type Preconnect, type DnsPrefetch } from '@rsbuild/shared';
|
|
3
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
4
|
+
type NetworkPerformanceType = 'preconnect' | 'dnsPrefetch';
|
|
5
|
+
export declare class HtmlNetworkPerformancePlugin implements RspackPluginInstance {
|
|
6
|
+
readonly options: DnsPrefetch | Preconnect;
|
|
7
|
+
readonly type: NetworkPerformanceType;
|
|
8
|
+
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
9
|
+
constructor(options: DnsPrefetch | Preconnect, type: NetworkPerformanceType, HtmlPlugin: typeof HtmlWebpackPlugin);
|
|
10
|
+
apply(compiler: Compiler): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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 HtmlNetworkPerformancePlugin_exports = {};
|
|
20
|
+
__export(HtmlNetworkPerformancePlugin_exports, {
|
|
21
|
+
HtmlNetworkPerformancePlugin: () => HtmlNetworkPerformancePlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(HtmlNetworkPerformancePlugin_exports);
|
|
24
|
+
var import_shared = require("@rsbuild/shared");
|
|
25
|
+
function generateLinks(options, type) {
|
|
26
|
+
const relMap = {
|
|
27
|
+
preconnect: "preconnect",
|
|
28
|
+
dnsPrefetch: "dns-prefetch"
|
|
29
|
+
};
|
|
30
|
+
return options.map((option) => ({
|
|
31
|
+
tagName: "link",
|
|
32
|
+
attributes: {
|
|
33
|
+
rel: relMap[type],
|
|
34
|
+
...option
|
|
35
|
+
},
|
|
36
|
+
voidTag: false,
|
|
37
|
+
meta: {}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
class HtmlNetworkPerformancePlugin {
|
|
41
|
+
constructor(options, type, HtmlPlugin) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
this.type = type;
|
|
44
|
+
this.HtmlPlugin = HtmlPlugin;
|
|
45
|
+
}
|
|
46
|
+
apply(compiler) {
|
|
47
|
+
compiler.hooks.compilation.tap(
|
|
48
|
+
`HTML${this.type}Plugin`,
|
|
49
|
+
(compilation) => {
|
|
50
|
+
this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(
|
|
51
|
+
`HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
|
|
52
|
+
(htmlPluginData) => {
|
|
53
|
+
const { headTags } = htmlPluginData;
|
|
54
|
+
const options = this.options.map(
|
|
55
|
+
(option) => typeof option === "string" ? {
|
|
56
|
+
href: option
|
|
57
|
+
} : option
|
|
58
|
+
);
|
|
59
|
+
if (options.length) {
|
|
60
|
+
headTags.unshift(...generateLinks(options, this.type));
|
|
61
|
+
}
|
|
62
|
+
return htmlPluginData;
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
HtmlNetworkPerformancePlugin
|
|
72
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
3
|
+
type NonceOptions = {
|
|
4
|
+
nonce: string;
|
|
5
|
+
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
6
|
+
};
|
|
7
|
+
export declare class HtmlNoncePlugin implements RspackPluginInstance {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly nonce: string;
|
|
10
|
+
readonly HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
11
|
+
constructor(options: NonceOptions);
|
|
12
|
+
apply(compiler: Compiler): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|