@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
|
@@ -0,0 +1,52 @@
|
|
|
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 HtmlNoncePlugin_exports = {};
|
|
20
|
+
__export(HtmlNoncePlugin_exports, {
|
|
21
|
+
HtmlNoncePlugin: () => HtmlNoncePlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(HtmlNoncePlugin_exports);
|
|
24
|
+
class HtmlNoncePlugin {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
const { nonce } = options;
|
|
27
|
+
this.name = "HtmlNoncePlugin";
|
|
28
|
+
this.nonce = nonce;
|
|
29
|
+
this.HtmlPlugin = options.HtmlPlugin;
|
|
30
|
+
}
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
if (!this.nonce) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
36
|
+
this.HtmlPlugin.getHooks(compilation).alterAssetTags.tap(
|
|
37
|
+
this.name,
|
|
38
|
+
(alterAssetTags) => {
|
|
39
|
+
const {
|
|
40
|
+
assetTags: { scripts }
|
|
41
|
+
} = alterAssetTags;
|
|
42
|
+
scripts.forEach((script) => script.attributes.nonce = this.nonce);
|
|
43
|
+
return alterAssetTags;
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
HtmlNoncePlugin
|
|
52
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2018 Google Inc.
|
|
4
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/determine-as-value.js
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import type { As } from './type';
|
|
19
|
+
export declare function determineAsValue({
|
|
20
|
+
href,
|
|
21
|
+
file
|
|
22
|
+
}: {
|
|
23
|
+
href: string;
|
|
24
|
+
file: string;
|
|
25
|
+
}): As;
|
|
@@ -0,0 +1,99 @@
|
|
|
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 determineAsValue_exports = {};
|
|
30
|
+
__export(determineAsValue_exports, {
|
|
31
|
+
determineAsValue: () => determineAsValue
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(determineAsValue_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_url = require("url");
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2018 Google Inc.
|
|
39
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/determine-as-value.js
|
|
40
|
+
*
|
|
41
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42
|
+
* you may not use this file except in compliance with the License.
|
|
43
|
+
* You may obtain a copy of the License at
|
|
44
|
+
*
|
|
45
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
46
|
+
*
|
|
47
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
48
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
49
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
50
|
+
* See the License for the specific language governing permissions and
|
|
51
|
+
* limitations under the License.
|
|
52
|
+
*/
|
|
53
|
+
function determineAsValue({
|
|
54
|
+
href,
|
|
55
|
+
file
|
|
56
|
+
}) {
|
|
57
|
+
const url = new import_url.URL(file || href, "https://example.com");
|
|
58
|
+
const extension = import_path.default.extname(url.pathname);
|
|
59
|
+
if ([".css"].includes(extension)) {
|
|
60
|
+
return "style";
|
|
61
|
+
}
|
|
62
|
+
if ([
|
|
63
|
+
".png",
|
|
64
|
+
".jpg",
|
|
65
|
+
".jpeg",
|
|
66
|
+
".jfif",
|
|
67
|
+
".pjpeg",
|
|
68
|
+
".pjp",
|
|
69
|
+
".svg",
|
|
70
|
+
".webp",
|
|
71
|
+
".bmp",
|
|
72
|
+
".apng",
|
|
73
|
+
".avif",
|
|
74
|
+
".gif",
|
|
75
|
+
".ico",
|
|
76
|
+
".cur",
|
|
77
|
+
".tif",
|
|
78
|
+
".tiff"
|
|
79
|
+
].includes(extension)) {
|
|
80
|
+
return "image";
|
|
81
|
+
}
|
|
82
|
+
if ([".mp4", ".ogg", ".webm"].includes(extension)) {
|
|
83
|
+
return "video";
|
|
84
|
+
}
|
|
85
|
+
if ([".mp3", ".wav"].includes(extension)) {
|
|
86
|
+
return "audio";
|
|
87
|
+
}
|
|
88
|
+
if ([".woff2", ".otf", ".ttf", ".woff", ".eot"].includes(extension)) {
|
|
89
|
+
return "font";
|
|
90
|
+
}
|
|
91
|
+
if ([".vtt"].includes(extension)) {
|
|
92
|
+
return "track";
|
|
93
|
+
}
|
|
94
|
+
return "script";
|
|
95
|
+
}
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
determineAsValue
|
|
99
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2018 Google Inc.
|
|
4
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/does-chunk-belong-to-html.js
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { Compilation } from '@rspack/core';
|
|
18
|
+
import type { Chunk } from 'webpack';
|
|
19
|
+
import type { PreloadOrPreFetchOption } from '@rsbuild/shared';
|
|
20
|
+
import { BeforeAssetTagGenerationHtmlPluginData } from './type';
|
|
21
|
+
interface DoesChunkBelongToHtmlOptions {
|
|
22
|
+
chunk: Chunk;
|
|
23
|
+
compilation?: Compilation;
|
|
24
|
+
htmlPluginData: BeforeAssetTagGenerationHtmlPluginData;
|
|
25
|
+
pluginOptions?: PreloadOrPreFetchOption;
|
|
26
|
+
}
|
|
27
|
+
export declare function doesChunkBelongToHtml({
|
|
28
|
+
chunk,
|
|
29
|
+
htmlPluginData
|
|
30
|
+
}: DoesChunkBelongToHtmlOptions): boolean;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
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 doesChunkBelongToHtml_exports = {};
|
|
20
|
+
__export(doesChunkBelongToHtml_exports, {
|
|
21
|
+
doesChunkBelongToHtml: () => doesChunkBelongToHtml
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(doesChunkBelongToHtml_exports);
|
|
24
|
+
/**
|
|
25
|
+
* @license
|
|
26
|
+
* Copyright 2018 Google Inc.
|
|
27
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/does-chunk-belong-to-html.js
|
|
28
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29
|
+
* you may not use this file except in compliance with the License.
|
|
30
|
+
* You may obtain a copy of the License at
|
|
31
|
+
*
|
|
32
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
35
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
37
|
+
* See the License for the specific language governing permissions and
|
|
38
|
+
* limitations under the License.
|
|
39
|
+
*/
|
|
40
|
+
function recursiveChunkGroup(chunkGroup) {
|
|
41
|
+
const parents = chunkGroup.getParents();
|
|
42
|
+
if (!parents.length) {
|
|
43
|
+
return [chunkGroup.name];
|
|
44
|
+
}
|
|
45
|
+
return parents.flatMap((chunkParent) => recursiveChunkGroup(chunkParent));
|
|
46
|
+
}
|
|
47
|
+
function recursiveChunkEntryNames(chunk) {
|
|
48
|
+
const isChunkName = (name) => Boolean(name);
|
|
49
|
+
const [...chunkGroups] = chunk.groupsIterable;
|
|
50
|
+
const names = chunkGroups.flatMap((chunkGroup) => recursiveChunkGroup(chunkGroup)).filter(isChunkName);
|
|
51
|
+
return [...new Set(names)];
|
|
52
|
+
}
|
|
53
|
+
function isChunksFiltered(chunkName, includeChunks, excludeChunks) {
|
|
54
|
+
if (Array.isArray(includeChunks) && includeChunks.indexOf(chunkName) === -1) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(excludeChunks) && excludeChunks.indexOf(chunkName) !== -1) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function doesChunkBelongToHtml({
|
|
63
|
+
chunk,
|
|
64
|
+
htmlPluginData
|
|
65
|
+
}) {
|
|
66
|
+
const { options } = htmlPluginData.plugin;
|
|
67
|
+
const chunkNames = recursiveChunkEntryNames(chunk);
|
|
68
|
+
return chunkNames.some(
|
|
69
|
+
(chunkName) => isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
doesChunkBelongToHtml
|
|
75
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2018 Google Inc.
|
|
4
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/extract-chunks.js
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { Chunk, Compilation } from 'webpack';
|
|
18
|
+
import type { PreloadIncludeType } from '@rsbuild/shared';
|
|
19
|
+
export type ChunkGroup = Compilation['chunkGroups'][0];
|
|
20
|
+
interface ExtractChunks {
|
|
21
|
+
compilation: Compilation;
|
|
22
|
+
includeType?: PreloadIncludeType;
|
|
23
|
+
}
|
|
24
|
+
export declare function extractChunks({
|
|
25
|
+
compilation,
|
|
26
|
+
includeType
|
|
27
|
+
}: ExtractChunks): Chunk[];
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
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 extractChunks_exports = {};
|
|
20
|
+
__export(extractChunks_exports, {
|
|
21
|
+
extractChunks: () => extractChunks
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extractChunks_exports);
|
|
24
|
+
/**
|
|
25
|
+
* @license
|
|
26
|
+
* Copyright 2018 Google Inc.
|
|
27
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/extract-chunks.js
|
|
28
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29
|
+
* you may not use this file except in compliance with the License.
|
|
30
|
+
* You may obtain a copy of the License at
|
|
31
|
+
*
|
|
32
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
35
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
37
|
+
* See the License for the specific language governing permissions and
|
|
38
|
+
* limitations under the License.
|
|
39
|
+
*/
|
|
40
|
+
function isAsync(chunk) {
|
|
41
|
+
if ("canBeInitial" in chunk) {
|
|
42
|
+
return !chunk.canBeInitial();
|
|
43
|
+
} else if ("isInitial" in chunk) {
|
|
44
|
+
return !chunk.isInitial();
|
|
45
|
+
}
|
|
46
|
+
return !chunk.initial;
|
|
47
|
+
}
|
|
48
|
+
function extractChunks({
|
|
49
|
+
compilation,
|
|
50
|
+
includeType
|
|
51
|
+
}) {
|
|
52
|
+
const chunks = [...compilation.chunks];
|
|
53
|
+
if (includeType === void 0 || includeType === "async-chunks") {
|
|
54
|
+
return chunks.filter(isAsync);
|
|
55
|
+
}
|
|
56
|
+
if (includeType === "initial") {
|
|
57
|
+
return chunks.filter((chunk) => !isAsync(chunk));
|
|
58
|
+
}
|
|
59
|
+
if (includeType === "all-chunks") {
|
|
60
|
+
return chunks;
|
|
61
|
+
}
|
|
62
|
+
if (includeType === "all-assets") {
|
|
63
|
+
const licenseAssets = [...compilation.assetsInfo.values()].map((info) => {
|
|
64
|
+
if (info.related?.license) {
|
|
65
|
+
return info.related.license;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}).filter(Boolean);
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
// @ts-expect-error ignore ts check for files
|
|
72
|
+
files: Object.keys(compilation.assets).filter(
|
|
73
|
+
(t) => !licenseAssets.includes(t)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
return chunks;
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
extractChunks
|
|
83
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var helpers_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
18
|
+
__reExport(helpers_exports, require("./extractChunks"), module.exports);
|
|
19
|
+
__reExport(helpers_exports, require("./determineAsValue"), module.exports);
|
|
20
|
+
__reExport(helpers_exports, require("./doesChunkBelongToHtml"), module.exports);
|
|
21
|
+
__reExport(helpers_exports, require("./type"), module.exports);
|
|
22
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
+
0 && (module.exports = {
|
|
24
|
+
...require("./extractChunks"),
|
|
25
|
+
...require("./determineAsValue"),
|
|
26
|
+
...require("./doesChunkBelongToHtml"),
|
|
27
|
+
...require("./type")
|
|
28
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
export type BeforeAssetTagGenerationHtmlPluginData = {
|
|
3
|
+
assets: {
|
|
4
|
+
publicPath: string;
|
|
5
|
+
js: Array<string>;
|
|
6
|
+
css: Array<string>;
|
|
7
|
+
favicon?: string;
|
|
8
|
+
manifest?: string;
|
|
9
|
+
};
|
|
10
|
+
outputName: string;
|
|
11
|
+
plugin: HtmlWebpackPlugin;
|
|
12
|
+
};
|
|
13
|
+
export type As = 'audio' | 'document' | 'embed' | 'fetch' | 'font' | 'image' | 'object' | 'script' | 'style' | 'track' | 'worker' | 'video';
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var type_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(type_exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2018 Google Inc.
|
|
4
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/index.js
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
18
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
19
|
+
import { type PreloadOrPreFetchOption } from '@rsbuild/shared';
|
|
20
|
+
type LinkType = 'preload' | 'prefetch';
|
|
21
|
+
export declare class HTMLPreloadOrPrefetchPlugin implements RspackPluginInstance {
|
|
22
|
+
readonly options: PreloadOrPreFetchOption;
|
|
23
|
+
resourceHints: HtmlWebpackPlugin.HtmlTagObject[];
|
|
24
|
+
type: LinkType;
|
|
25
|
+
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
26
|
+
HTMLCount: number;
|
|
27
|
+
constructor(options: true | PreloadOrPreFetchOption, type: LinkType, HtmlPlugin: typeof HtmlWebpackPlugin, HTMLCount: number);
|
|
28
|
+
apply(compiler: Compiler): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
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 HtmlPreloadOrPrefetchPlugin_exports = {};
|
|
20
|
+
__export(HtmlPreloadOrPrefetchPlugin_exports, {
|
|
21
|
+
HTMLPreloadOrPrefetchPlugin: () => HTMLPreloadOrPrefetchPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(HtmlPreloadOrPrefetchPlugin_exports);
|
|
24
|
+
var import_shared = require("@rsbuild/shared");
|
|
25
|
+
var import_helpers = require("./helpers");
|
|
26
|
+
/**
|
|
27
|
+
* @license
|
|
28
|
+
* Copyright 2018 Google Inc.
|
|
29
|
+
* https://github.com/vuejs/preload-webpack-plugin/blob/master/src/index.js
|
|
30
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License.
|
|
32
|
+
* You may obtain a copy of the License at
|
|
33
|
+
*
|
|
34
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
* See the License for the specific language governing permissions and
|
|
40
|
+
* limitations under the License.
|
|
41
|
+
*/
|
|
42
|
+
const defaultOptions = {
|
|
43
|
+
type: "async-chunks"
|
|
44
|
+
};
|
|
45
|
+
function filterResourceHints(resourceHints, scripts) {
|
|
46
|
+
return resourceHints.filter(
|
|
47
|
+
(resourceHint) => !scripts.find(
|
|
48
|
+
(script) => script.attributes.src === resourceHint.attributes.href
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
|
|
53
|
+
const extractedChunks = (0, import_helpers.extractChunks)({
|
|
54
|
+
// @ts-expect-error compilation type mismatch
|
|
55
|
+
compilation,
|
|
56
|
+
includeType: options.type
|
|
57
|
+
});
|
|
58
|
+
const htmlChunks = (
|
|
59
|
+
// Handle all chunks.
|
|
60
|
+
options.type === "all-assets" || HTMLCount === 1 ? extractedChunks : extractedChunks.filter(
|
|
61
|
+
(chunk) => (
|
|
62
|
+
// TODO: Not yet supported in rspack, maybe we should implement it in another way
|
|
63
|
+
// https://github.com/web-infra-dev/rspack/issues/3896
|
|
64
|
+
(0, import_helpers.doesChunkBelongToHtml)({
|
|
65
|
+
chunk,
|
|
66
|
+
compilation,
|
|
67
|
+
htmlPluginData,
|
|
68
|
+
pluginOptions: options
|
|
69
|
+
})
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
const allFiles = htmlChunks.reduce(
|
|
74
|
+
(accumulated, chunk) => accumulated.concat([
|
|
75
|
+
...chunk.files,
|
|
76
|
+
// sourcemap files are inside auxiliaryFiles in webpack5
|
|
77
|
+
...chunk.auxiliaryFiles || []
|
|
78
|
+
]),
|
|
79
|
+
[]
|
|
80
|
+
);
|
|
81
|
+
const uniqueFiles = new Set(allFiles);
|
|
82
|
+
const filteredFiles = [...uniqueFiles].filter((file) => [/.map$/].every((regex) => !regex.test(file))).filter(
|
|
83
|
+
(file) => !options.include || (typeof options.include === "function" ? options.include(file) : options.include.some((regex) => new RegExp(regex).test(file)))
|
|
84
|
+
).filter(
|
|
85
|
+
(file) => !options.exclude || (typeof options.exclude === "function" ? !options.exclude(file) : options.exclude.every((regex) => !new RegExp(regex).test(file)))
|
|
86
|
+
);
|
|
87
|
+
const sortedFilteredFiles = filteredFiles.sort();
|
|
88
|
+
const links = [];
|
|
89
|
+
const publicPath = (0, import_shared.getPublicPathFromCompiler)(compilation.compiler);
|
|
90
|
+
const { crossOriginLoading } = compilation.compiler.options.output;
|
|
91
|
+
for (const file of sortedFilteredFiles) {
|
|
92
|
+
const href = (0, import_shared.withPublicPath)(file, publicPath);
|
|
93
|
+
const attributes = {
|
|
94
|
+
href,
|
|
95
|
+
rel: type
|
|
96
|
+
};
|
|
97
|
+
if (type === "preload") {
|
|
98
|
+
attributes.as = (0, import_helpers.determineAsValue)({
|
|
99
|
+
href,
|
|
100
|
+
file
|
|
101
|
+
});
|
|
102
|
+
if (attributes.as === "font") {
|
|
103
|
+
attributes.crossorigin = "";
|
|
104
|
+
}
|
|
105
|
+
if (attributes.as === "script" || attributes.as === "style") {
|
|
106
|
+
if (crossOriginLoading && !(crossOriginLoading !== "use-credentials" && publicPath === "/")) {
|
|
107
|
+
attributes.crossorigin = crossOriginLoading === "anonymous" ? "" : crossOriginLoading;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
links.push({
|
|
112
|
+
tagName: "link",
|
|
113
|
+
attributes,
|
|
114
|
+
voidTag: true,
|
|
115
|
+
meta: {}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return links;
|
|
119
|
+
}
|
|
120
|
+
class HTMLPreloadOrPrefetchPlugin {
|
|
121
|
+
constructor(options, type, HtmlPlugin, HTMLCount) {
|
|
122
|
+
this.resourceHints = [];
|
|
123
|
+
this.options = {
|
|
124
|
+
...defaultOptions,
|
|
125
|
+
...typeof options === "boolean" ? {} : options
|
|
126
|
+
};
|
|
127
|
+
this.type = type;
|
|
128
|
+
this.HtmlPlugin = HtmlPlugin;
|
|
129
|
+
this.HTMLCount = HTMLCount;
|
|
130
|
+
}
|
|
131
|
+
apply(compiler) {
|
|
132
|
+
compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
|
|
133
|
+
this.HtmlPlugin.getHooks(compilation).beforeAssetTagGeneration.tap(
|
|
134
|
+
`HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
|
|
135
|
+
(htmlPluginData) => {
|
|
136
|
+
this.resourceHints = generateLinks(
|
|
137
|
+
this.options,
|
|
138
|
+
this.type,
|
|
139
|
+
compilation,
|
|
140
|
+
htmlPluginData,
|
|
141
|
+
this.HTMLCount
|
|
142
|
+
);
|
|
143
|
+
return htmlPluginData;
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
this.HtmlPlugin.getHooks(compilation).alterAssetTags.tap(
|
|
147
|
+
`HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
|
|
148
|
+
(htmlPluginData) => {
|
|
149
|
+
if (this.resourceHints) {
|
|
150
|
+
htmlPluginData.assetTags.styles = [
|
|
151
|
+
...filterResourceHints(
|
|
152
|
+
this.resourceHints,
|
|
153
|
+
htmlPluginData.assetTags.scripts
|
|
154
|
+
),
|
|
155
|
+
...htmlPluginData.assetTags.styles
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
return htmlPluginData;
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
HTMLPreloadOrPrefetchPlugin
|
|
167
|
+
});
|