@rsbuild/core 0.7.0-beta.2 → 0.7.0-beta.4

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 (181) hide show
  1. package/bin/rsbuild.js +4 -3
  2. package/compiled/css-loader/index.js +20 -20
  3. package/compiled/less-loader/index.js +8 -8
  4. package/compiled/postcss-loader/index.js +11 -11
  5. package/compiled/rspack-manifest-plugin/index.js +4 -4
  6. package/dist/client/{hmr.mjs → hmr.js} +2 -3
  7. package/dist/client/{overlay.mjs → overlay.js} +2 -6
  8. package/dist/{rspack/ignoreCssLoader.js → ignoreCssLoader.cjs} +2 -0
  9. package/dist/index.cjs +7201 -0
  10. package/dist/index.js +7435 -40
  11. package/dist/{rspack/transformLoader.js → transformLoader.cjs} +2 -0
  12. package/dist/{rspack/transformRawLoader.js → transformRawLoader.cjs} +37 -13
  13. package/{dist → dist-types}/constants.d.ts +3 -0
  14. package/dist-types/helpers.d.ts +32 -0
  15. package/{dist → dist-types}/index.d.ts +6 -0
  16. package/{dist → dist-types}/internal.d.ts +5 -2
  17. package/dist-types/package.json +1 -0
  18. package/{dist → dist-types}/plugins/html.d.ts +2 -1
  19. package/{dist → dist-types}/plugins/index.d.ts +1 -0
  20. package/dist-types/plugins/minimize.d.ts +12 -0
  21. package/{dist/provider → dist-types}/plugins/progress.d.ts +1 -1
  22. package/{dist/provider → dist-types}/plugins/resolve.d.ts +1 -1
  23. package/{dist/provider → dist-types}/plugins/rspackProfile.d.ts +1 -1
  24. package/{dist/provider → dist-types}/plugins/swc.d.ts +1 -1
  25. package/dist-types/server/devMiddleware.d.ts +18 -0
  26. package/{dist → dist-types}/server/helper.d.ts +11 -0
  27. package/package.json +14 -16
  28. package/dist/cli/commands.js +0 -110
  29. package/dist/cli/init.js +0 -101
  30. package/dist/cli/prepare.js +0 -43
  31. package/dist/client/format.js +0 -72
  32. package/dist/config.js +0 -306
  33. package/dist/constants.js +0 -40
  34. package/dist/createContext.js +0 -116
  35. package/dist/createRsbuild.js +0 -103
  36. package/dist/initHooks.js +0 -82
  37. package/dist/initPlugins.js +0 -152
  38. package/dist/internal.js +0 -79
  39. package/dist/loadEnv.js +0 -93
  40. package/dist/mergeConfig.js +0 -80
  41. package/dist/pluginHelper.js +0 -66
  42. package/dist/pluginManager.js +0 -180
  43. package/dist/plugins/asset.js +0 -101
  44. package/dist/plugins/basic.js +0 -77
  45. package/dist/plugins/bundleAnalyzer.js +0 -69
  46. package/dist/plugins/cache.js +0 -116
  47. package/dist/plugins/cleanOutput.js +0 -68
  48. package/dist/plugins/css.js +0 -257
  49. package/dist/plugins/define.js +0 -45
  50. package/dist/plugins/entry.js +0 -76
  51. package/dist/plugins/externals.js +0 -48
  52. package/dist/plugins/fileSize.js +0 -199
  53. package/dist/plugins/html.js +0 -327
  54. package/dist/plugins/index.js +0 -66
  55. package/dist/plugins/inlineChunk.js +0 -69
  56. package/dist/plugins/less.js +0 -107
  57. package/dist/plugins/manifest.js +0 -142
  58. package/dist/plugins/moduleFederation.js +0 -125
  59. package/dist/plugins/moment.js +0 -43
  60. package/dist/plugins/nodeAddons.js +0 -74
  61. package/dist/plugins/output.js +0 -63
  62. package/dist/plugins/performance.js +0 -56
  63. package/dist/plugins/resourceHints.js +0 -86
  64. package/dist/plugins/rsdoctor.js +0 -81
  65. package/dist/plugins/sass.js +0 -154
  66. package/dist/plugins/server.js +0 -59
  67. package/dist/plugins/splitChunks.js +0 -236
  68. package/dist/plugins/startUrl.js +0 -146
  69. package/dist/plugins/target.js +0 -54
  70. package/dist/plugins/wasm.js +0 -51
  71. package/dist/provider/build.js +0 -84
  72. package/dist/provider/createCompiler.js +0 -143
  73. package/dist/provider/initConfigs.js +0 -92
  74. package/dist/provider/inspectConfig.js +0 -85
  75. package/dist/provider/plugins/minimize.d.ts +0 -2
  76. package/dist/provider/plugins/minimize.js +0 -49
  77. package/dist/provider/plugins/progress.js +0 -49
  78. package/dist/provider/plugins/resolve.js +0 -42
  79. package/dist/provider/plugins/rspackProfile.js +0 -112
  80. package/dist/provider/plugins/swc.js +0 -152
  81. package/dist/provider/plugins/transition.d.ts +0 -5
  82. package/dist/provider/plugins/transition.js +0 -35
  83. package/dist/provider/provider.js +0 -158
  84. package/dist/provider/rspackConfig.js +0 -144
  85. package/dist/provider/shared.d.ts +0 -16
  86. package/dist/provider/shared.js +0 -215
  87. package/dist/rspack/HtmlAppIconPlugin.js +0 -98
  88. package/dist/rspack/HtmlBasicPlugin.js +0 -229
  89. package/dist/rspack/InlineChunkHtmlPlugin.js +0 -196
  90. package/dist/rspack/preload/HtmlPreloadOrPrefetchPlugin.js +0 -173
  91. package/dist/rspack/preload/helpers/determineAsValue.js +0 -83
  92. package/dist/rspack/preload/helpers/doesChunkBelongToHtml.js +0 -77
  93. package/dist/rspack/preload/helpers/extractChunks.js +0 -83
  94. package/dist/rspack/preload/helpers/index.js +0 -28
  95. package/dist/rspack/preload/helpers/type.js +0 -16
  96. package/dist/server/compilerDevMiddleware.js +0 -129
  97. package/dist/server/devMiddleware.d.ts +0 -3
  98. package/dist/server/devMiddleware.js +0 -74
  99. package/dist/server/devServer.js +0 -195
  100. package/dist/server/getDevMiddlewares.js +0 -177
  101. package/dist/server/helper.js +0 -237
  102. package/dist/server/httpServer.js +0 -45
  103. package/dist/server/index.js +0 -31
  104. package/dist/server/middlewares.js +0 -162
  105. package/dist/server/prodServer.js +0 -196
  106. package/dist/server/proxy.js +0 -93
  107. package/dist/server/restart.js +0 -66
  108. package/dist/server/socketServer.js +0 -178
  109. package/dist/server/watchFiles.js +0 -90
  110. package/dist/types.js +0 -16
  111. /package/{dist → dist-types}/cli/commands.d.ts +0 -0
  112. /package/{dist → dist-types}/cli/init.d.ts +0 -0
  113. /package/{dist → dist-types}/cli/prepare.d.ts +0 -0
  114. /package/{dist → dist-types}/client/format.d.ts +0 -0
  115. /package/{dist → dist-types}/client/hmr.d.ts +0 -0
  116. /package/{dist → dist-types}/client/overlay.d.ts +0 -0
  117. /package/{dist → dist-types}/config.d.ts +0 -0
  118. /package/{dist → dist-types}/createContext.d.ts +0 -0
  119. /package/{dist → dist-types}/createRsbuild.d.ts +0 -0
  120. /package/{dist → dist-types}/initHooks.d.ts +0 -0
  121. /package/{dist → dist-types}/initPlugins.d.ts +0 -0
  122. /package/{dist → dist-types}/loadEnv.d.ts +0 -0
  123. /package/{dist/rspack → dist-types/loader}/ignoreCssLoader.d.ts +0 -0
  124. /package/{dist/rspack → dist-types/loader}/transformLoader.d.ts +0 -0
  125. /package/{dist/rspack → dist-types/loader}/transformRawLoader.d.ts +0 -0
  126. /package/{dist → dist-types}/mergeConfig.d.ts +0 -0
  127. /package/{dist → dist-types}/pluginHelper.d.ts +0 -0
  128. /package/{dist → dist-types}/pluginManager.d.ts +0 -0
  129. /package/{dist → dist-types}/plugins/asset.d.ts +0 -0
  130. /package/{dist → dist-types}/plugins/basic.d.ts +0 -0
  131. /package/{dist → dist-types}/plugins/bundleAnalyzer.d.ts +0 -0
  132. /package/{dist → dist-types}/plugins/cache.d.ts +0 -0
  133. /package/{dist → dist-types}/plugins/cleanOutput.d.ts +0 -0
  134. /package/{dist → dist-types}/plugins/css.d.ts +0 -0
  135. /package/{dist → dist-types}/plugins/define.d.ts +0 -0
  136. /package/{dist → dist-types}/plugins/entry.d.ts +0 -0
  137. /package/{dist → dist-types}/plugins/externals.d.ts +0 -0
  138. /package/{dist → dist-types}/plugins/fileSize.d.ts +0 -0
  139. /package/{dist → dist-types}/plugins/inlineChunk.d.ts +0 -0
  140. /package/{dist → dist-types}/plugins/less.d.ts +0 -0
  141. /package/{dist → dist-types}/plugins/manifest.d.ts +0 -0
  142. /package/{dist → dist-types}/plugins/moduleFederation.d.ts +0 -0
  143. /package/{dist → dist-types}/plugins/moment.d.ts +0 -0
  144. /package/{dist → dist-types}/plugins/nodeAddons.d.ts +0 -0
  145. /package/{dist → dist-types}/plugins/output.d.ts +0 -0
  146. /package/{dist → dist-types}/plugins/performance.d.ts +0 -0
  147. /package/{dist → dist-types}/plugins/resourceHints.d.ts +0 -0
  148. /package/{dist → dist-types}/plugins/rsdoctor.d.ts +0 -0
  149. /package/{dist → dist-types}/plugins/sass.d.ts +0 -0
  150. /package/{dist → dist-types}/plugins/server.d.ts +0 -0
  151. /package/{dist → dist-types}/plugins/splitChunks.d.ts +0 -0
  152. /package/{dist → dist-types}/plugins/startUrl.d.ts +0 -0
  153. /package/{dist → dist-types}/plugins/target.d.ts +0 -0
  154. /package/{dist → dist-types}/plugins/wasm.d.ts +0 -0
  155. /package/{dist → dist-types}/provider/build.d.ts +0 -0
  156. /package/{dist → dist-types}/provider/createCompiler.d.ts +0 -0
  157. /package/{dist → dist-types}/provider/initConfigs.d.ts +0 -0
  158. /package/{dist → dist-types}/provider/inspectConfig.d.ts +0 -0
  159. /package/{dist → dist-types}/provider/provider.d.ts +0 -0
  160. /package/{dist → dist-types}/provider/rspackConfig.d.ts +0 -0
  161. /package/{dist → dist-types}/rspack/HtmlAppIconPlugin.d.ts +0 -0
  162. /package/{dist → dist-types}/rspack/HtmlBasicPlugin.d.ts +0 -0
  163. /package/{dist → dist-types}/rspack/InlineChunkHtmlPlugin.d.ts +0 -0
  164. /package/{dist → dist-types}/rspack/preload/HtmlPreloadOrPrefetchPlugin.d.ts +0 -0
  165. /package/{dist → dist-types}/rspack/preload/helpers/determineAsValue.d.ts +0 -0
  166. /package/{dist → dist-types}/rspack/preload/helpers/doesChunkBelongToHtml.d.ts +0 -0
  167. /package/{dist → dist-types}/rspack/preload/helpers/extractChunks.d.ts +0 -0
  168. /package/{dist → dist-types}/rspack/preload/helpers/index.d.ts +0 -0
  169. /package/{dist → dist-types}/rspack/preload/helpers/type.d.ts +0 -0
  170. /package/{dist → dist-types}/server/compilerDevMiddleware.d.ts +0 -0
  171. /package/{dist → dist-types}/server/devServer.d.ts +0 -0
  172. /package/{dist → dist-types}/server/getDevMiddlewares.d.ts +0 -0
  173. /package/{dist → dist-types}/server/httpServer.d.ts +0 -0
  174. /package/{dist → dist-types}/server/index.d.ts +0 -0
  175. /package/{dist → dist-types}/server/middlewares.d.ts +0 -0
  176. /package/{dist → dist-types}/server/prodServer.d.ts +0 -0
  177. /package/{dist → dist-types}/server/proxy.d.ts +0 -0
  178. /package/{dist → dist-types}/server/restart.d.ts +0 -0
  179. /package/{dist → dist-types}/server/socketServer.d.ts +0 -0
  180. /package/{dist → dist-types}/server/watchFiles.d.ts +0 -0
  181. /package/{dist → dist-types}/types.d.ts +0 -0
@@ -1,196 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
- var InlineChunkHtmlPlugin_exports = {};
25
- __export(InlineChunkHtmlPlugin_exports, {
26
- InlineChunkHtmlPlugin: () => InlineChunkHtmlPlugin
27
- });
28
- module.exports = __toCommonJS(InlineChunkHtmlPlugin_exports);
29
- var import_node_path = require("node:path");
30
- var import_shared = require("@rsbuild/shared");
31
- var import_pluginHelper = require("../pluginHelper");
32
- class InlineChunkHtmlPlugin {
33
- constructor({
34
- styleTests,
35
- scriptTests,
36
- distPath
37
- }) {
38
- __publicField(this, "name");
39
- __publicField(this, "styleTests");
40
- __publicField(this, "scriptTests");
41
- __publicField(this, "distPath");
42
- __publicField(this, "inlinedAssets");
43
- this.name = "InlineChunkHtmlPlugin";
44
- this.styleTests = styleTests;
45
- this.scriptTests = scriptTests;
46
- this.distPath = distPath;
47
- this.inlinedAssets = /* @__PURE__ */ new Set();
48
- }
49
- /**
50
- * If we inlined the chunk to HTML,we should update the value of sourceMappingURL,
51
- * because the relative path of source code has been changed.
52
- * @param source
53
- */
54
- updateSourceMappingURL({
55
- source,
56
- compilation,
57
- publicPath,
58
- type
59
- }) {
60
- const { devtool } = compilation.options;
61
- if (devtool && // If the source map is inlined, we do not need to update the sourceMappingURL
62
- !devtool.includes("inline") && source.includes("# sourceMappingURL")) {
63
- const prefix = (0, import_shared.addTrailingSlash)(
64
- (0, import_node_path.join)(publicPath, this.distPath[type] || "")
65
- );
66
- return source.replace(
67
- /# sourceMappingURL=/,
68
- `# sourceMappingURL=${prefix}`
69
- );
70
- }
71
- return source;
72
- }
73
- matchTests(name, source, tests) {
74
- return tests.some((test) => {
75
- if ((0, import_shared.isFunction)(test)) {
76
- const size = source.length;
77
- return test({ name, size });
78
- }
79
- return test.exec(name);
80
- });
81
- }
82
- getInlinedScriptTag(publicPath, tag, compilation) {
83
- const { assets } = compilation;
84
- if (!(tag?.attributes.src && typeof tag.attributes.src === "string")) {
85
- return tag;
86
- }
87
- const { src, ...otherAttrs } = tag.attributes;
88
- const scriptName = publicPath ? src.replace(publicPath, "") : src;
89
- const asset = assets[scriptName];
90
- if (asset == null) {
91
- return tag;
92
- }
93
- const source = asset.source().toString();
94
- const shouldInline = this.matchTests(scriptName, source, this.scriptTests);
95
- if (!shouldInline) {
96
- return tag;
97
- }
98
- const ret = {
99
- tagName: "script",
100
- innerHTML: this.updateSourceMappingURL({
101
- source,
102
- compilation,
103
- publicPath,
104
- type: "js"
105
- }),
106
- attributes: {
107
- ...otherAttrs
108
- },
109
- closeTag: true
110
- };
111
- this.inlinedAssets.add(scriptName);
112
- return ret;
113
- }
114
- getInlinedCSSTag(publicPath, tag, compilation) {
115
- const { assets } = compilation;
116
- if (!(tag.attributes.href && typeof tag.attributes.href === "string")) {
117
- return tag;
118
- }
119
- const linkName = publicPath ? tag.attributes.href.replace(publicPath, "") : tag.attributes.href;
120
- const asset = assets[linkName];
121
- if (asset == null) {
122
- return tag;
123
- }
124
- const source = asset.source().toString();
125
- const shouldInline = this.matchTests(linkName, source, this.styleTests);
126
- if (!shouldInline) {
127
- return tag;
128
- }
129
- const ret = {
130
- tagName: "style",
131
- innerHTML: this.updateSourceMappingURL({
132
- source,
133
- compilation,
134
- publicPath,
135
- type: "css"
136
- }),
137
- closeTag: true
138
- };
139
- this.inlinedAssets.add(linkName);
140
- return ret;
141
- }
142
- getInlinedTag(publicPath, tag, compilation) {
143
- if (tag.tagName === "script") {
144
- return this.getInlinedScriptTag(
145
- publicPath,
146
- tag,
147
- compilation
148
- );
149
- }
150
- if (tag.tagName === "link" && tag.attributes && tag.attributes.rel === "stylesheet") {
151
- return this.getInlinedCSSTag(
152
- publicPath,
153
- tag,
154
- compilation
155
- );
156
- }
157
- return tag;
158
- }
159
- apply(compiler) {
160
- compiler.hooks.compilation.tap(this.name, (compilation) => {
161
- const publicPath = (0, import_shared.getPublicPathFromCompiler)(compiler);
162
- const tagFunction = (tag) => this.getInlinedTag(publicPath, tag, compilation);
163
- const hooks = (0, import_pluginHelper.getHTMLPlugin)().getHooks(compilation);
164
- hooks.alterAssetTagGroups.tap(this.name, (assets) => {
165
- assets.headTags = assets.headTags.map(tagFunction);
166
- assets.bodyTags = assets.bodyTags.map(tagFunction);
167
- return assets;
168
- });
169
- compilation.hooks.processAssets.tap(
170
- {
171
- name: "InlineChunkHtmlPlugin",
172
- /**
173
- * Remove marked inline assets in summarize stage,
174
- * which should be later than the emitting of html-webpack-plugin
175
- */
176
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
177
- },
178
- () => {
179
- const { devtool } = compiler.options;
180
- for (const name of this.inlinedAssets) {
181
- if (devtool === "hidden-source-map") {
182
- compilation.deleteAsset(name);
183
- } else {
184
- delete compilation.assets[name];
185
- }
186
- }
187
- this.inlinedAssets.clear();
188
- }
189
- );
190
- });
191
- }
192
- }
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- InlineChunkHtmlPlugin
196
- });
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
- var HtmlPreloadOrPrefetchPlugin_exports = {};
25
- __export(HtmlPreloadOrPrefetchPlugin_exports, {
26
- HtmlPreloadOrPrefetchPlugin: () => HtmlPreloadOrPrefetchPlugin
27
- });
28
- module.exports = __toCommonJS(HtmlPreloadOrPrefetchPlugin_exports);
29
- var import_shared = require("@rsbuild/shared");
30
- var import_pluginHelper = require("../../pluginHelper");
31
- var import_helpers = require("./helpers");
32
- /**
33
- * @license
34
- * Copyright 2018 Google Inc.
35
- * https://github.com/vuejs/preload-webpack-plugin/blob/master/src/index.js
36
- * Licensed under the Apache License, Version 2.0 (the "License");
37
- * you may not use this file except in compliance with the License.
38
- * You may obtain a copy of the License at
39
- *
40
- * http://www.apache.org/licenses/LICENSE-2.0
41
- *
42
- * Unless required by applicable law or agreed to in writing, software
43
- * distributed under the License is distributed on an "AS IS" BASIS,
44
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
- * See the License for the specific language governing permissions and
46
- * limitations under the License.
47
- */
48
- const defaultOptions = {
49
- type: "async-chunks"
50
- };
51
- function filterResourceHints(resourceHints, scripts) {
52
- return resourceHints.filter(
53
- (resourceHint) => !scripts.find(
54
- (script) => script.attributes.src === resourceHint.attributes.href
55
- )
56
- );
57
- }
58
- function generateLinks(options, type, compilation, htmlPluginData, HTMLCount) {
59
- const extractedChunks = (0, import_helpers.extractChunks)({
60
- compilation,
61
- includeType: options.type
62
- });
63
- const htmlChunks = (
64
- // Handle all chunks.
65
- options.type === "all-assets" || HTMLCount === 1 ? extractedChunks : (
66
- // Only handle chunks imported by this HtmlWebpackPlugin.
67
- extractedChunks.filter(
68
- (chunk) => (0, import_helpers.doesChunkBelongToHtml)({
69
- chunk,
70
- compilation,
71
- htmlPluginData,
72
- pluginOptions: options
73
- })
74
- )
75
- )
76
- );
77
- const allFiles = htmlChunks.reduce(
78
- (accumulated, chunk) => accumulated.concat([
79
- ...chunk.files,
80
- // sourcemap files are inside auxiliaryFiles in webpack5
81
- ...chunk.auxiliaryFiles || []
82
- ]),
83
- []
84
- );
85
- const uniqueFiles = new Set(allFiles);
86
- const filteredFiles = [...uniqueFiles].filter((file) => [/.map$/].every((regex) => !regex.test(file))).filter(
87
- (file) => !options.include || (typeof options.include === "function" ? options.include(file) : options.include.some((regex) => new RegExp(regex).test(file)))
88
- ).filter(
89
- (file) => !options.exclude || (typeof options.exclude === "function" ? !options.exclude(file) : options.exclude.every((regex) => !new RegExp(regex).test(file)))
90
- );
91
- const sortedFilteredFiles = filteredFiles.sort();
92
- const links = [];
93
- const publicPath = (0, import_shared.getPublicPathFromCompiler)(compilation.compiler);
94
- const { crossOriginLoading } = compilation.compiler.options.output;
95
- for (const file of sortedFilteredFiles) {
96
- const href = (0, import_shared.withPublicPath)(file, publicPath);
97
- const attributes = {
98
- href,
99
- rel: type
100
- };
101
- if (type === "preload") {
102
- attributes.as = (0, import_helpers.determineAsValue)({
103
- href,
104
- file
105
- });
106
- if (attributes.as === "font") {
107
- attributes.crossorigin = "";
108
- }
109
- if (attributes.as === "script" || attributes.as === "style") {
110
- if (crossOriginLoading && !(crossOriginLoading !== "use-credentials" && publicPath === "/")) {
111
- attributes.crossorigin = crossOriginLoading === "anonymous" ? "" : crossOriginLoading;
112
- }
113
- }
114
- }
115
- links.push({
116
- tagName: "link",
117
- attributes,
118
- voidTag: true,
119
- meta: {}
120
- });
121
- }
122
- return links;
123
- }
124
- class HtmlPreloadOrPrefetchPlugin {
125
- constructor(options, type, HTMLCount) {
126
- __publicField(this, "options");
127
- __publicField(this, "resourceHints", []);
128
- __publicField(this, "type");
129
- __publicField(this, "HTMLCount");
130
- this.options = {
131
- ...defaultOptions,
132
- ...typeof options === "boolean" ? {} : options
133
- };
134
- this.type = type;
135
- this.HTMLCount = HTMLCount;
136
- }
137
- apply(compiler) {
138
- compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
139
- (0, import_pluginHelper.getHTMLPlugin)().getHooks(compilation).beforeAssetTagGeneration.tap(
140
- `HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
141
- (htmlPluginData) => {
142
- this.resourceHints = generateLinks(
143
- this.options,
144
- this.type,
145
- compilation,
146
- htmlPluginData,
147
- this.HTMLCount
148
- );
149
- return htmlPluginData;
150
- }
151
- );
152
- (0, import_pluginHelper.getHTMLPlugin)().getHooks(compilation).alterAssetTags.tap(
153
- `HTML${(0, import_shared.upperFirst)(this.type)}Plugin`,
154
- (htmlPluginData) => {
155
- if (this.resourceHints) {
156
- htmlPluginData.assetTags.styles = [
157
- ...filterResourceHints(
158
- this.resourceHints,
159
- htmlPluginData.assetTags.scripts
160
- ),
161
- ...htmlPluginData.assetTags.styles
162
- ];
163
- }
164
- return htmlPluginData;
165
- }
166
- );
167
- });
168
- }
169
- }
170
- // Annotate the CommonJS export names for ESM import in node:
171
- 0 && (module.exports = {
172
- HtmlPreloadOrPrefetchPlugin
173
- });
@@ -1,83 +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 determineAsValue_exports = {};
30
- __export(determineAsValue_exports, {
31
- determineAsValue: () => determineAsValue
32
- });
33
- module.exports = __toCommonJS(determineAsValue_exports);
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_node_url = require("node:url");
36
- var import_shared = require("@rsbuild/shared");
37
- /**
38
- * @license
39
- * Copyright 2018 Google Inc.
40
- * https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/determine-as-value.js
41
- *
42
- * Licensed under the Apache License, Version 2.0 (the "License");
43
- * you may not use this file except in compliance with the License.
44
- * You may obtain a copy of the License at
45
- *
46
- * http://www.apache.org/licenses/LICENSE-2.0
47
- *
48
- * Unless required by applicable law or agreed to in writing, software
49
- * distributed under the License is distributed on an "AS IS" BASIS,
50
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51
- * See the License for the specific language governing permissions and
52
- * limitations under the License.
53
- */
54
- function determineAsValue({
55
- href,
56
- file
57
- }) {
58
- const url = new import_node_url.URL(file || href, "https://example.com");
59
- const extension = import_node_path.default.extname(url.pathname).slice(1);
60
- if (["css"].includes(extension)) {
61
- return "style";
62
- }
63
- if (import_shared.IMAGE_EXTENSIONS.includes(extension)) {
64
- return "image";
65
- }
66
- if (import_shared.VIDEO_EXTENSIONS.includes(extension)) {
67
- return "video";
68
- }
69
- if (import_shared.AUDIO_EXTENSIONS.includes(extension)) {
70
- return "audio";
71
- }
72
- if (import_shared.FONT_EXTENSIONS.includes(extension)) {
73
- return "font";
74
- }
75
- if (["vtt"].includes(extension)) {
76
- return "track";
77
- }
78
- return "script";
79
- }
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- determineAsValue
83
- });
@@ -1,77 +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 doesChunkBelongToHtml_exports = {};
20
- __export(doesChunkBelongToHtml_exports, {
21
- doesChunkBelongToHtml: () => doesChunkBelongToHtml,
22
- recursiveChunkEntryNames: () => recursiveChunkEntryNames
23
- });
24
- module.exports = __toCommonJS(doesChunkBelongToHtml_exports);
25
- /**
26
- * @license
27
- * Copyright 2018 Google Inc.
28
- * https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/does-chunk-belong-to-html.js
29
- * Licensed under the Apache License, Version 2.0 (the "License");
30
- * you may not use this file except in compliance with the License.
31
- * You may obtain a copy of the License at
32
- *
33
- * http://www.apache.org/licenses/LICENSE-2.0
34
- *
35
- * Unless required by applicable law or agreed to in writing, software
36
- * distributed under the License is distributed on an "AS IS" BASIS,
37
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
- * See the License for the specific language governing permissions and
39
- * limitations under the License.
40
- */
41
- function recursiveChunkGroup(chunkGroup) {
42
- const parents = chunkGroup.getParents();
43
- if (!parents.length) {
44
- return [chunkGroup.name];
45
- }
46
- return parents.flatMap((chunkParent) => recursiveChunkGroup(chunkParent));
47
- }
48
- function recursiveChunkEntryNames(chunk) {
49
- const isChunkName = (name) => Boolean(name);
50
- const [...chunkGroups] = chunk.groupsIterable;
51
- const names = chunkGroups.flatMap((chunkGroup) => recursiveChunkGroup(chunkGroup)).filter(isChunkName);
52
- return [...new Set(names)];
53
- }
54
- function isChunksFiltered(chunkName, includeChunks, excludeChunks) {
55
- if (Array.isArray(includeChunks) && includeChunks.indexOf(chunkName) === -1) {
56
- return false;
57
- }
58
- if (Array.isArray(excludeChunks) && excludeChunks.indexOf(chunkName) !== -1) {
59
- return false;
60
- }
61
- return true;
62
- }
63
- function doesChunkBelongToHtml({
64
- chunk,
65
- htmlPluginData
66
- }) {
67
- const { options } = htmlPluginData.plugin;
68
- const chunkNames = recursiveChunkEntryNames(chunk);
69
- return chunkNames.some(
70
- (chunkName) => isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks)
71
- );
72
- }
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- doesChunkBelongToHtml,
76
- recursiveChunkEntryNames
77
- });
@@ -1,83 +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 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
- }
44
- if ("isInitial" in chunk) {
45
- return !chunk.isInitial();
46
- }
47
- return !chunk.initial;
48
- }
49
- function extractChunks({
50
- compilation,
51
- includeType
52
- }) {
53
- const chunks = [...compilation.chunks];
54
- if (includeType === void 0 || includeType === "async-chunks") {
55
- return chunks.filter(isAsync);
56
- }
57
- if (includeType === "initial") {
58
- return chunks.filter((chunk) => !isAsync(chunk));
59
- }
60
- if (includeType === "all-chunks") {
61
- return chunks;
62
- }
63
- if (includeType === "all-assets") {
64
- const licenseAssets = [...compilation.assetsInfo?.values() || []].map((info) => {
65
- if (info.related?.license) {
66
- return info.related.license;
67
- }
68
- return false;
69
- }).filter(Boolean);
70
- return [
71
- {
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
- });
@@ -1,28 +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 __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
- });
@@ -1,16 +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 __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);