@modern-js/builder 2.46.1 → 3.0.0-alpha.0

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.
Files changed (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +14 -16
  3. package/compiled/postcss-load-config/index.d.ts +1 -0
  4. package/compiled/postcss-load-config/index.js +14 -0
  5. package/compiled/postcss-load-config/license +20 -0
  6. package/compiled/postcss-load-config/package.json +1 -0
  7. package/dist/createBuilder.d.ts +8 -2
  8. package/dist/createBuilder.js +124 -39
  9. package/dist/index.d.ts +8 -4
  10. package/dist/index.js +18 -7
  11. package/dist/plugins/babel-post.d.ts +5 -0
  12. package/dist/plugins/{asset.js → babel-post.js} +21 -22
  13. package/dist/plugins/devtools.d.ts +4 -0
  14. package/dist/plugins/{devtool.js → devtools.js} +15 -16
  15. package/dist/plugins/emitRouteFile.d.ts +6 -0
  16. package/dist/plugins/{cleanOutput.js → emitRouteFile.js} +34 -16
  17. package/dist/plugins/environmentDefaults.d.ts +3 -0
  18. package/dist/plugins/environmentDefaults.js +99 -0
  19. package/dist/plugins/globalVars.d.ts +3 -0
  20. package/dist/plugins/{moment.js → globalVars.js} +23 -16
  21. package/dist/plugins/htmlMinify.d.ts +2 -0
  22. package/dist/plugins/htmlMinify.js +126 -0
  23. package/dist/plugins/manifest.d.ts +2 -0
  24. package/dist/plugins/{entry.js → manifest.js} +18 -16
  25. package/dist/plugins/postcss.d.ts +6 -0
  26. package/dist/plugins/postcss.js +133 -0
  27. package/dist/plugins/runtimeChunk.d.ts +2 -0
  28. package/dist/plugins/runtimeChunk.js +55 -0
  29. package/dist/rsc/common.d.ts +22 -0
  30. package/dist/rsc/common.js +174 -0
  31. package/dist/rsc/plugins/rsbuild-rsc-plugin.d.ts +7 -0
  32. package/dist/rsc/plugins/rsbuild-rsc-plugin.js +166 -0
  33. package/dist/rsc/plugins/rspack-rsc-client-plugin.d.ts +14 -0
  34. package/dist/rsc/plugins/rspack-rsc-client-plugin.js +233 -0
  35. package/dist/rsc/plugins/rspack-rsc-server-plugin.d.ts +32 -0
  36. package/dist/rsc/plugins/rspack-rsc-server-plugin.js +290 -0
  37. package/dist/rsc/rsc-client-loader.d.ts +7 -0
  38. package/dist/rsc/rsc-client-loader.js +70 -0
  39. package/dist/rsc/rsc-css-loader.d.ts +2 -0
  40. package/dist/{plugins/yaml.js → rsc/rsc-css-loader.js} +11 -17
  41. package/dist/rsc/rsc-server-loader.d.ts +6 -0
  42. package/dist/rsc/rsc-server-loader.js +95 -0
  43. package/dist/rsc/rsc-ssr-loader.d.ts +6 -0
  44. package/dist/rsc/rsc-ssr-loader.js +58 -0
  45. package/dist/shared/devServer.d.ts +6 -0
  46. package/dist/shared/devServer.js +83 -0
  47. package/dist/shared/getCssSupport.d.ts +1 -0
  48. package/dist/shared/getCssSupport.js +113 -0
  49. package/dist/shared/manifest.d.ts +2 -0
  50. package/dist/{plugins/toml.js → shared/manifest.js} +16 -14
  51. package/dist/shared/parseCommonConfig.d.ts +8 -0
  52. package/dist/shared/parseCommonConfig.js +232 -0
  53. package/dist/shared/utils.d.ts +12 -0
  54. package/dist/shared/utils.js +109 -0
  55. package/dist/types.d.ts +283 -0
  56. package/dist/types.js +16 -0
  57. package/package.json +54 -59
  58. package/dist/cli/commands.d.ts +0 -2
  59. package/dist/cli/commands.js +0 -45
  60. package/dist/cli/config.d.ts +0 -14
  61. package/dist/cli/config.js +0 -72
  62. package/dist/cli/index.d.ts +0 -6
  63. package/dist/cli/index.js +0 -51
  64. package/dist/cli/provider.d.ts +0 -2
  65. package/dist/cli/provider.js +0 -73
  66. package/dist/plugins/antd.d.ts +0 -3
  67. package/dist/plugins/antd.js +0 -63
  68. package/dist/plugins/arco.d.ts +0 -2
  69. package/dist/plugins/arco.js +0 -61
  70. package/dist/plugins/asset.d.ts +0 -2
  71. package/dist/plugins/assetsRetry.d.ts +0 -2
  72. package/dist/plugins/assetsRetry.js +0 -64
  73. package/dist/plugins/bundleAnalyzer.d.ts +0 -2
  74. package/dist/plugins/bundleAnalyzer.js +0 -59
  75. package/dist/plugins/cache.d.ts +0 -2
  76. package/dist/plugins/cache.js +0 -129
  77. package/dist/plugins/checkSyntax.d.ts +0 -2
  78. package/dist/plugins/checkSyntax.js +0 -73
  79. package/dist/plugins/cleanOutput.d.ts +0 -2
  80. package/dist/plugins/define.d.ts +0 -2
  81. package/dist/plugins/define.js +0 -68
  82. package/dist/plugins/devtool.d.ts +0 -2
  83. package/dist/plugins/entry.d.ts +0 -2
  84. package/dist/plugins/externals.d.ts +0 -2
  85. package/dist/plugins/externals.js +0 -48
  86. package/dist/plugins/fileSize.d.ts +0 -4
  87. package/dist/plugins/fileSize.js +0 -164
  88. package/dist/plugins/html.d.ts +0 -3
  89. package/dist/plugins/html.js +0 -236
  90. package/dist/plugins/index.d.ts +0 -2
  91. package/dist/plugins/index.js +0 -74
  92. package/dist/plugins/inlineChunk.d.ts +0 -2
  93. package/dist/plugins/inlineChunk.js +0 -82
  94. package/dist/plugins/moment.d.ts +0 -2
  95. package/dist/plugins/networkPerformance.d.ts +0 -2
  96. package/dist/plugins/networkPerformance.js +0 -54
  97. package/dist/plugins/nodeAddons.d.ts +0 -2
  98. package/dist/plugins/nodeAddons.js +0 -73
  99. package/dist/plugins/performance.d.ts +0 -5
  100. package/dist/plugins/performance.js +0 -66
  101. package/dist/plugins/preloadOrPrefetch.d.ts +0 -2
  102. package/dist/plugins/preloadOrPrefetch.js +0 -57
  103. package/dist/plugins/rem.d.ts +0 -2
  104. package/dist/plugins/rem.js +0 -106
  105. package/dist/plugins/sourceBuild.d.ts +0 -15
  106. package/dist/plugins/sourceBuild.js +0 -121
  107. package/dist/plugins/splitChunks.d.ts +0 -4
  108. package/dist/plugins/splitChunks.js +0 -249
  109. package/dist/plugins/startUrl.d.ts +0 -3
  110. package/dist/plugins/startUrl.js +0 -86
  111. package/dist/plugins/svg.d.ts +0 -2
  112. package/dist/plugins/svg.js +0 -89
  113. package/dist/plugins/target.d.ts +0 -2
  114. package/dist/plugins/target.js +0 -73
  115. package/dist/plugins/toml.d.ts +0 -2
  116. package/dist/plugins/tsChecker.d.ts +0 -2
  117. package/dist/plugins/tsChecker.js +0 -109
  118. package/dist/plugins/wasm.d.ts +0 -2
  119. package/dist/plugins/wasm.js +0 -51
  120. package/dist/plugins/yaml.d.ts +0 -2
  121. package/vitest.config.ts +0 -19
@@ -1,48 +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 __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 externals_exports = {};
20
- __export(externals_exports, {
21
- builderPluginExternals: () => builderPluginExternals
22
- });
23
- module.exports = __toCommonJS(externals_exports);
24
- function builderPluginExternals() {
25
- return {
26
- name: "builder-plugin-externals",
27
- setup(api) {
28
- api.modifyBundlerChain((chain) => {
29
- const { externals } = api.getNormalizedConfig().output;
30
- if (externals) {
31
- chain.externals(externals);
32
- }
33
- });
34
- api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
35
- bundlerConfigs.forEach((config) => {
36
- const isWebWorker = Array.isArray(config.target) ? config.target.includes("webworker") : config.target === "webworker";
37
- if (isWebWorker && config.externals) {
38
- delete config.externals;
39
- }
40
- });
41
- });
42
- }
43
- };
44
- }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- builderPluginExternals
48
- });
@@ -1,4 +0,0 @@
1
- import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- /** Filter source map and license files */
3
- export declare const filterAsset: (asset: string) => boolean;
4
- export declare const builderPluginFileSize: () => DefaultBuilderPlugin;
@@ -1,164 +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 fileSize_exports = {};
30
- __export(fileSize_exports, {
31
- builderPluginFileSize: () => builderPluginFileSize,
32
- filterAsset: () => filterAsset
33
- });
34
- module.exports = __toCommonJS(fileSize_exports);
35
- var import_path = __toESM(require("path"));
36
- var import_chalk = __toESM(require("@modern-js/utils/chalk"));
37
- var import_builder_shared = require("@modern-js/builder-shared");
38
- const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
39
- const getAssetColor = (size) => {
40
- if (size > 300 * 1e3) {
41
- return import_chalk.default.bold.red;
42
- }
43
- if (size > 100 * 1e3) {
44
- return import_chalk.default.yellow;
45
- }
46
- return import_chalk.default.green;
47
- };
48
- async function printHeader(longestFileLength, longestLabelLength) {
49
- const longestLengths = [
50
- longestFileLength,
51
- longestLabelLength
52
- ];
53
- const headerRow = [
54
- "File",
55
- "Size",
56
- "Gzipped"
57
- ].reduce((prev, cur, index) => {
58
- const length = longestLengths[index];
59
- let curLabel = cur;
60
- if (length) {
61
- curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
62
- }
63
- return `${prev + curLabel} `;
64
- }, " ");
65
- import_builder_shared.logger.log(import_chalk.default.bold.blue(headerRow));
66
- }
67
- async function printFileSizes(stats, distPath) {
68
- const { fs, filesize, gzipSize, stripAnsi } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
69
- const formatAsset = (asset) => {
70
- const fileName = asset.name.split("?")[0];
71
- const contents = fs.readFileSync(import_path.default.join(distPath, fileName));
72
- const size = contents.length;
73
- const gzippedSize = gzipSize.sync(contents);
74
- return {
75
- size,
76
- folder: import_path.default.join(import_path.default.basename(distPath), import_path.default.dirname(fileName)),
77
- name: import_path.default.basename(fileName),
78
- gzippedSize,
79
- sizeLabel: filesize(size, {
80
- round: 1
81
- }),
82
- gzipSizeLabel: getAssetColor(gzippedSize)(filesize(gzippedSize, {
83
- round: 1
84
- }))
85
- };
86
- };
87
- const multiStats = "stats" in stats ? stats.stats : [
88
- stats
89
- ];
90
- const assets = multiStats.map((stats2) => {
91
- const origin = stats2.toJson({
92
- all: false,
93
- assets: true,
94
- cachedAssets: true,
95
- groupAssetsByInfo: false,
96
- groupAssetsByPath: false,
97
- groupAssetsByChunk: false,
98
- groupAssetsByExtension: false,
99
- groupAssetsByEmitStatus: false
100
- });
101
- const filteredAssets = origin.assets.filter((asset) => filterAsset(asset.name));
102
- return filteredAssets.map(formatAsset);
103
- }).reduce((single, all) => all.concat(single), []);
104
- if (assets.length === 0) {
105
- return;
106
- }
107
- assets.sort((a, b) => b.size - a.size);
108
- const longestLabelLength = Math.max(...assets.map((a) => stripAnsi(a.sizeLabel).length));
109
- const longestFileLength = Math.max(...assets.map((a) => stripAnsi(a.folder + import_path.default.sep + a.name).length));
110
- import_builder_shared.logger.info(`Production file sizes:
111
- `);
112
- printHeader(longestFileLength, longestLabelLength);
113
- let totalSize = 0;
114
- let totalGzipSize = 0;
115
- assets.forEach((asset) => {
116
- let { sizeLabel } = asset;
117
- const { name, folder, gzipSizeLabel } = asset;
118
- const fileNameLength = stripAnsi(folder + import_path.default.sep + name).length;
119
- const sizeLength = stripAnsi(sizeLabel).length;
120
- totalSize += asset.size;
121
- totalGzipSize += asset.gzippedSize;
122
- if (sizeLength < longestLabelLength) {
123
- const rightPadding = " ".repeat(longestLabelLength - sizeLength);
124
- sizeLabel += rightPadding;
125
- }
126
- let fileNameLabel = import_chalk.default.dim(asset.folder + import_path.default.sep) + import_chalk.default.cyan(asset.name);
127
- if (fileNameLength < longestFileLength) {
128
- const rightPadding = " ".repeat(longestFileLength - fileNameLength);
129
- fileNameLabel += rightPadding;
130
- }
131
- import_builder_shared.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
132
- });
133
- const totalSizeLabel = `${import_chalk.default.bold.blue("Total size:")} ${filesize(totalSize, {
134
- round: 1
135
- })}`;
136
- const gzippedSizeLabel = `${import_chalk.default.bold.blue("Gzipped size:")} ${filesize(totalGzipSize, {
137
- round: 1
138
- })}`;
139
- import_builder_shared.logger.log(`
140
- ${totalSizeLabel}
141
- ${gzippedSizeLabel}
142
- `);
143
- }
144
- const builderPluginFileSize = () => ({
145
- name: "builder-plugin-file-size",
146
- setup(api) {
147
- api.onAfterBuild(async ({ stats }) => {
148
- const config = api.getNormalizedConfig();
149
- if (config.performance.printFileSize && stats) {
150
- try {
151
- await printFileSizes(stats, api.context.distPath);
152
- } catch (err) {
153
- import_builder_shared.logger.error("Failed to print file size.");
154
- import_builder_shared.logger.error(err);
155
- }
156
- }
157
- });
158
- }
159
- });
160
- // Annotate the CommonJS export names for ESM import in node:
161
- 0 && (module.exports = {
162
- builderPluginFileSize,
163
- filterAsset
164
- });
@@ -1,3 +0,0 @@
1
- import type { DefaultBuilderPlugin, SharedBuilderPluginAPI } from '@modern-js/builder-shared';
2
- export declare const applyInjectTags: (api: SharedBuilderPluginAPI) => void;
3
- export declare const builderPluginHtml: () => DefaultBuilderPlugin;
@@ -1,236 +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 html_exports = {};
30
- __export(html_exports, {
31
- applyInjectTags: () => applyInjectTags,
32
- builderPluginHtml: () => builderPluginHtml
33
- });
34
- module.exports = __toCommonJS(html_exports);
35
- var import_path = __toESM(require("path"));
36
- var import_builder_shared = require("@modern-js/builder-shared");
37
- var import_lodash = __toESM(require("@modern-js/utils/lodash"));
38
- async function getTemplateParameters(entryName, config, assetPrefix) {
39
- const { applyOptionsChain } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
40
- const { mountId, templateParameters, templateParametersByEntries } = config.html;
41
- const meta = await (0, import_builder_shared.getMetaTags)(entryName, config);
42
- const title = (0, import_builder_shared.getTitle)(entryName, config);
43
- const templateParams = (templateParametersByEntries === null || templateParametersByEntries === void 0 ? void 0 : templateParametersByEntries[entryName]) || templateParameters;
44
- const baseParameters = {
45
- meta,
46
- title,
47
- mountId,
48
- entryName,
49
- assetPrefix
50
- };
51
- return (compilation, assets, assetTags, pluginOptions) => {
52
- const defaultOptions = {
53
- compilation,
54
- webpackConfig: compilation.options,
55
- htmlWebpackPlugin: {
56
- tags: assetTags,
57
- files: assets,
58
- options: pluginOptions
59
- },
60
- ...baseParameters
61
- };
62
- return applyOptionsChain(defaultOptions, templateParams);
63
- };
64
- }
65
- async function getChunks(entryName, entryValue) {
66
- const { isPlainObject } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
67
- const dependOn = [];
68
- if (isPlainObject(entryValue)) {
69
- dependOn.push(...entryValue.dependOn);
70
- }
71
- return [
72
- ...dependOn,
73
- entryName
74
- ];
75
- }
76
- const applyInjectTags = (api) => {
77
- api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID }) => {
78
- const config = api.getNormalizedConfig();
79
- const tags = import_lodash.default.castArray(config.html.tags).filter(Boolean);
80
- const tagsByEntries = import_lodash.default.mapValues(config.html.tagsByEntries, (tags2) => import_lodash.default.castArray(tags2).filter(Boolean));
81
- const shouldByEntries = import_lodash.default.some(tagsByEntries, "length");
82
- if (!tags.length && !shouldByEntries) {
83
- return;
84
- }
85
- const { HtmlTagsPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
86
- const sharedOptions = {
87
- HtmlPlugin,
88
- append: true,
89
- hash: false,
90
- publicPath: true,
91
- tags
92
- };
93
- if (tags.length && !shouldByEntries) {
94
- chain.plugin(CHAIN_ID.PLUGIN.HTML_TAGS).use(HtmlTagsPlugin, [
95
- sharedOptions
96
- ]);
97
- return;
98
- }
99
- for (const [entry, filename] of Object.entries(api.getHTMLPaths())) {
100
- const opts = {
101
- ...sharedOptions,
102
- includes: [
103
- filename
104
- ]
105
- };
106
- entry in tagsByEntries && (opts.tags = tagsByEntries[entry]);
107
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML_TAGS}#${entry}`).use(HtmlTagsPlugin, [
108
- opts
109
- ]);
110
- }
111
- });
112
- };
113
- const builderPluginHtml = () => ({
114
- name: "builder-plugin-html",
115
- setup(api) {
116
- const routesInfo = [];
117
- api.modifyBundlerChain(async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
118
- const config = api.getNormalizedConfig();
119
- if ((0, import_builder_shared.isHtmlDisabled)(config, target)) {
120
- return;
121
- }
122
- const { removeTailSlash, applyOptionsChain } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
123
- const minify = await (0, import_builder_shared.getMinify)(isProd, config);
124
- const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
125
- const entries = chain.entryPoints.entries() || {};
126
- const entryNames = Object.keys(entries);
127
- const htmlPaths = api.getHTMLPaths();
128
- const faviconUrls = [];
129
- await Promise.all(entryNames.map(async (entryName, index) => {
130
- const entryValue = entries[entryName].values();
131
- const chunks = await getChunks(entryName, entryValue);
132
- const inject = (0, import_builder_shared.getInject)(entryName, config);
133
- const favicon = (0, import_builder_shared.getFavicon)(entryName, config);
134
- const filename = htmlPaths[entryName];
135
- const template = (0, import_builder_shared.getTemplatePath)(entryName, config);
136
- const templateParameters = await getTemplateParameters(entryName, config, assetPrefix);
137
- const pluginOptions = {
138
- chunks,
139
- inject,
140
- minify,
141
- filename,
142
- template,
143
- templateParameters,
144
- scriptLoading: config.html.scriptLoading
145
- };
146
- if (favicon) {
147
- if ((0, import_builder_shared.isURL)(favicon)) {
148
- faviconUrls.push({
149
- filename,
150
- url: favicon
151
- });
152
- } else {
153
- pluginOptions.favicon = favicon;
154
- }
155
- }
156
- const finalOptions = applyOptionsChain(pluginOptions, config.tools.htmlPlugin, {
157
- entryName,
158
- entryValue
159
- });
160
- routesInfo.push({
161
- urlPath: index === 0 ? "/" : `/${entryName}`,
162
- entryName,
163
- entryPath: filename,
164
- isSPA: true
165
- });
166
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [
167
- finalOptions
168
- ]);
169
- }));
170
- if (config.security) {
171
- const { nonce } = config.security;
172
- if (nonce) {
173
- const { HtmlNoncePlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
174
- chain.plugin(CHAIN_ID.PLUGIN.HTML_NONCE).use(HtmlNoncePlugin, [
175
- {
176
- nonce,
177
- HtmlPlugin
178
- }
179
- ]);
180
- }
181
- }
182
- if (config.html) {
183
- const { appIcon, crossorigin } = config.html;
184
- if (crossorigin) {
185
- const { HtmlCrossOriginPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
186
- const formattedCrossorigin = crossorigin === true ? "anonymous" : crossorigin;
187
- chain.plugin(CHAIN_ID.PLUGIN.HTML_CROSS_ORIGIN).use(HtmlCrossOriginPlugin, [
188
- {
189
- crossOrigin: formattedCrossorigin,
190
- HtmlPlugin
191
- }
192
- ]);
193
- chain.output.crossOriginLoading(formattedCrossorigin);
194
- }
195
- if (faviconUrls.length) {
196
- const { HtmlFaviconUrlPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
197
- chain.plugin(CHAIN_ID.PLUGIN.FAVICON_URL).use(HtmlFaviconUrlPlugin, [
198
- {
199
- faviconUrls,
200
- HtmlPlugin
201
- }
202
- ]);
203
- }
204
- if (appIcon) {
205
- const { HtmlAppIconPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
206
- const distDir = (0, import_builder_shared.getDistPath)(config.output, "image");
207
- const iconPath = import_path.default.isAbsolute(appIcon) ? appIcon : import_path.default.join(api.context.rootPath, appIcon);
208
- chain.plugin(CHAIN_ID.PLUGIN.APP_ICON).use(HtmlAppIconPlugin, [
209
- {
210
- iconPath,
211
- distDir,
212
- HtmlPlugin
213
- }
214
- ]);
215
- }
216
- }
217
- });
218
- const emitRouteJson = async () => {
219
- const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
220
- const routeFilePath = import_path.default.join(api.context.distPath, ROUTE_SPEC_FILE);
221
- if (!await (0, import_builder_shared.isFileExists)(routeFilePath) && routesInfo.length) {
222
- await fs.outputFile(routeFilePath, JSON.stringify({
223
- routes: routesInfo
224
- }, null, 2));
225
- }
226
- };
227
- api.onBeforeBuild(emitRouteJson);
228
- api.onBeforeStartDevServer(emitRouteJson);
229
- applyInjectTags(api);
230
- }
231
- });
232
- // Annotate the CommonJS export names for ESM import in node:
233
- 0 && (module.exports = {
234
- applyInjectTags,
235
- builderPluginHtml
236
- });
@@ -1,2 +0,0 @@
1
- import { Plugins } from '@modern-js/builder-shared';
2
- export declare const plugins: Plugins;
@@ -1,74 +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 plugins_exports = {};
30
- __export(plugins_exports, {
31
- plugins: () => plugins
32
- });
33
- module.exports = __toCommonJS(plugins_exports);
34
- var import_builder_shared = require("@modern-js/builder-shared");
35
- const plugins = {
36
- html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.builderPluginHtml()),
37
- cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.builderPluginCleanOutput()),
38
- startUrl: () => Promise.resolve().then(() => __toESM(require("./startUrl"))).then((m) => m.builderPluginStartUrl()),
39
- fileSize: () => Promise.resolve().then(() => __toESM(require("./fileSize"))).then((m) => m.builderPluginFileSize()),
40
- devtool: () => Promise.resolve().then(() => __toESM(require("./devtool"))).then((m) => m.builderPluginDevtool()),
41
- target: () => Promise.resolve().then(() => __toESM(require("./target"))).then((m) => m.builderPluginTarget()),
42
- entry: () => Promise.resolve().then(() => __toESM(require("./entry"))).then((m) => m.builderPluginEntry()),
43
- cache: () => Promise.resolve().then(() => __toESM(require("./cache"))).then((m) => m.builderPluginCache()),
44
- yaml: () => Promise.resolve().then(() => __toESM(require("./yaml"))).then((m) => m.builderPluginYaml()),
45
- toml: () => Promise.resolve().then(() => __toESM(require("./toml"))).then((m) => m.builderPluginToml()),
46
- svg: () => Promise.resolve().then(() => __toESM(require("./svg"))).then((m) => m.builderPluginSvg()),
47
- splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.builderPluginSplitChunks()),
48
- inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.builderPluginInlineChunk()),
49
- bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.builderPluginBundleAnalyzer()),
50
- font: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.builderAssetPlugin("font", import_builder_shared.FONT_EXTENSIONS)),
51
- image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.builderAssetPlugin("image", import_builder_shared.IMAGE_EXTENSIONS)),
52
- media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.builderAssetPlugin("media", import_builder_shared.MEDIA_EXTENSIONS)),
53
- assetsRetry: () => Promise.resolve().then(() => __toESM(require("./assetsRetry"))).then((m) => m.builderPluginAssetsRetry()),
54
- antd: () => Promise.resolve().then(() => __toESM(require("./antd"))).then((m) => m.builderPluginAntd()),
55
- arco: () => Promise.resolve().then(() => __toESM(require("./arco"))).then((m) => m.builderPluginArco()),
56
- tsChecker: () => Promise.resolve().then(() => __toESM(require("./tsChecker"))).then((m) => m.builderPluginTsChecker()),
57
- checkSyntax: () => Promise.resolve().then(() => __toESM(require("./checkSyntax"))).then((m) => m.builderPluginCheckSyntax()),
58
- rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.builderPluginRem()),
59
- wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.builderPluginWasm()),
60
- moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.builderPluginMoment()),
61
- nodeAddons: () => Promise.resolve().then(() => __toESM(require("./nodeAddons"))).then((m) => m.builderPluginNodeAddons()),
62
- externals: () => Promise.resolve().then(() => __toESM(require("./externals"))).then((m) => m.builderPluginExternals()),
63
- sourceBuild: () => Promise.resolve().then(() => __toESM(require("./sourceBuild"))).then((m) => m.builderPluginSourceBuild({
64
- sourceField: "source"
65
- })),
66
- networkPerformance: () => Promise.resolve().then(() => __toESM(require("./networkPerformance"))).then((m) => m.builderPluginNetworkPerformance()),
67
- preloadOrPrefetch: () => Promise.resolve().then(() => __toESM(require("./preloadOrPrefetch"))).then((m) => m.builderPluginPreloadOrPrefetch()),
68
- performance: () => Promise.resolve().then(() => __toESM(require("./performance"))).then((m) => m.builderPluginPerformance()),
69
- define: () => Promise.resolve().then(() => __toESM(require("./define"))).then((m) => m.builderPluginDefine())
70
- };
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- plugins
74
- });
@@ -1,2 +0,0 @@
1
- import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginInlineChunk: () => DefaultBuilderPlugin;
@@ -1,82 +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 inlineChunk_exports = {};
30
- __export(inlineChunk_exports, {
31
- builderPluginInlineChunk: () => builderPluginInlineChunk
32
- });
33
- module.exports = __toCommonJS(inlineChunk_exports);
34
- var import_builder_shared = require("@modern-js/builder-shared");
35
- const builderPluginInlineChunk = () => ({
36
- name: "builder-plugin-inline-chunk",
37
- setup(api) {
38
- api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
39
- const config = api.getNormalizedConfig();
40
- if ((0, import_builder_shared.isHtmlDisabled)(config, target) || !isProd) {
41
- return;
42
- }
43
- const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
44
- const {
45
- disableInlineRuntimeChunk,
46
- enableInlineStyles,
47
- // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
48
- enableInlineScripts
49
- } = config.output;
50
- const scriptTests = [];
51
- const styleTests = [];
52
- if (enableInlineScripts) {
53
- scriptTests.push(enableInlineScripts === true ? import_builder_shared.JS_REGEX : enableInlineScripts);
54
- }
55
- if (enableInlineStyles) {
56
- styleTests.push(enableInlineStyles === true ? import_builder_shared.CSS_REGEX : enableInlineStyles);
57
- }
58
- if (!disableInlineRuntimeChunk) {
59
- scriptTests.push(
60
- // RegExp like /builder-runtime([.].+)?\.js$/
61
- // matches builder-runtime.js and builder-runtime.123456.js
62
- new RegExp(`${import_builder_shared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
63
- );
64
- }
65
- chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
66
- HtmlPlugin,
67
- {
68
- styleTests,
69
- scriptTests,
70
- distPath: (0, import_builder_shared.pick)(config.output.distPath, [
71
- "js",
72
- "css"
73
- ])
74
- }
75
- ]);
76
- });
77
- }
78
- });
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- builderPluginInlineChunk
82
- });
@@ -1,2 +0,0 @@
1
- import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginMoment: () => DefaultBuilderPlugin;
@@ -1,2 +0,0 @@
1
- import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginNetworkPerformance: () => DefaultBuilderPlugin;