@rsbuild/core 0.0.28 → 0.1.1
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/compiled/dotenv/index.js +1 -0
- package/compiled/dotenv/lib/main.d.ts +156 -0
- package/compiled/dotenv/license +23 -0
- package/compiled/dotenv/package.json +1 -0
- package/compiled/dotenv-expand/index.js +1 -0
- package/compiled/dotenv-expand/lib/main.d.ts +29 -0
- package/compiled/dotenv-expand/license +24 -0
- package/compiled/dotenv-expand/package.json +1 -0
- package/dist/cli/commands.d.ts +7 -1
- package/dist/cli/commands.js +37 -24
- package/dist/cli/config.js +28 -16
- package/dist/cli/prepare.js +1 -1
- package/dist/client/hmr.js +187 -187
- package/dist/loadEnv.d.ts +5 -0
- package/dist/loadEnv.js +58 -0
- package/dist/plugins/asset.js +1 -1
- package/dist/plugins/bundleAnalyzer.js +1 -1
- package/dist/plugins/cache.js +1 -1
- package/dist/plugins/cleanOutput.js +1 -1
- package/dist/plugins/define.js +1 -1
- package/dist/plugins/devtool.js +1 -1
- package/dist/plugins/entry.js +1 -1
- package/dist/plugins/externals.js +1 -1
- package/dist/plugins/fileSize.js +5 -4
- package/dist/plugins/html.d.ts +6 -4
- package/dist/plugins/html.js +39 -27
- package/dist/plugins/inlineChunk.js +8 -12
- package/dist/plugins/moment.js +1 -1
- package/dist/plugins/nodeAddons.js +1 -1
- package/dist/plugins/performance.js +1 -1
- package/dist/plugins/splitChunks.js +1 -1
- package/dist/plugins/startUrl.js +1 -1
- package/dist/plugins/target.js +1 -1
- package/dist/plugins/toml.js +1 -1
- package/dist/plugins/wasm.js +1 -1
- package/dist/plugins/yaml.js +1 -1
- package/dist/rspack-plugins/HtmlBasicPlugin.d.ts +2 -2
- package/dist/rspack-plugins/HtmlBasicPlugin.js +9 -17
- package/dist/rspack-provider/core/createContext.js +1 -1
- package/dist/rspack-provider/plugins/basic.js +1 -1
- package/dist/rspack-provider/plugins/css.js +1 -1
- package/dist/rspack-provider/plugins/hmr.js +1 -1
- package/dist/rspack-provider/plugins/less.js +1 -1
- package/dist/rspack-provider/plugins/minimize.js +1 -1
- package/dist/rspack-provider/plugins/output.js +1 -1
- package/dist/rspack-provider/plugins/progress.js +1 -1
- package/dist/rspack-provider/plugins/resolve.js +1 -1
- package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
- package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
- package/dist/rspack-provider/plugins/sass.js +1 -1
- package/dist/rspack-provider/plugins/swc.js +3 -4
- package/dist/rspack-provider/plugins/transition.js +1 -5
- package/dist/server/dev-middleware/index.d.ts +5 -2
- package/dist/server/dev-middleware/index.js +24 -5
- package/dist/server/devServer.js +11 -12
- package/dist/server/middlewares.d.ts +2 -2
- package/dist/server/middlewares.js +19 -12
- package/dist/server/prodServer.d.ts +6 -3
- package/dist/server/prodServer.js +52 -11
- package/dist/server/proxy.d.ts +4 -3
- package/dist/server/restart.js +4 -1
- package/package.json +4 -4
- package/dist/server/https.d.ts +0 -6
- package/dist/server/https.js +0 -50
package/dist/plugins/html.js
CHANGED
|
@@ -29,11 +29,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var html_exports = {};
|
|
30
30
|
__export(html_exports, {
|
|
31
31
|
applyInjectTags: () => applyInjectTags,
|
|
32
|
-
generateMetaTags: () => generateMetaTags,
|
|
33
32
|
getFavicon: () => getFavicon,
|
|
34
33
|
getInject: () => getInject,
|
|
35
34
|
getMetaTags: () => getMetaTags,
|
|
36
|
-
|
|
35
|
+
getTemplate: () => getTemplate,
|
|
37
36
|
getTitle: () => getTitle,
|
|
38
37
|
pluginHtml: () => pluginHtml
|
|
39
38
|
});
|
|
@@ -57,17 +56,39 @@ function getInject(entryName, config) {
|
|
|
57
56
|
useObjectParam: true
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
|
-
|
|
59
|
+
const existTemplatePath = [];
|
|
60
|
+
async function getTemplate(entryName, config, rootPath) {
|
|
61
61
|
const DEFAULT_TEMPLATE = import_path.default.resolve(
|
|
62
62
|
__dirname,
|
|
63
63
|
"../../static/template.html"
|
|
64
64
|
);
|
|
65
|
-
|
|
65
|
+
const templatePath = (0, import_shared.mergeChainedOptions)({
|
|
66
66
|
defaults: DEFAULT_TEMPLATE,
|
|
67
67
|
options: config.html.template,
|
|
68
68
|
utils: { entryName },
|
|
69
69
|
useObjectParam: true
|
|
70
70
|
});
|
|
71
|
+
if (templatePath === DEFAULT_TEMPLATE) {
|
|
72
|
+
return {
|
|
73
|
+
templatePath
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const absolutePath = (0, import_path.isAbsolute)(templatePath) ? templatePath : import_path.default.resolve(rootPath, templatePath);
|
|
77
|
+
if (!existTemplatePath.includes(absolutePath)) {
|
|
78
|
+
if (!await (0, import_shared.isFileExists)(absolutePath)) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Failed to resolve HTML template, please check if the file exists: ${import_shared.color.cyan(
|
|
81
|
+
absolutePath
|
|
82
|
+
)}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
existTemplatePath.push(absolutePath);
|
|
86
|
+
}
|
|
87
|
+
const templateContent = await import_shared.fse.readFile(absolutePath, "utf-8");
|
|
88
|
+
return {
|
|
89
|
+
templatePath: absolutePath,
|
|
90
|
+
templateContent
|
|
91
|
+
};
|
|
71
92
|
}
|
|
72
93
|
function getFavicon(entryName, config) {
|
|
73
94
|
return (0, import_shared.mergeChainedOptions)({
|
|
@@ -77,26 +98,13 @@ function getFavicon(entryName, config) {
|
|
|
77
98
|
useObjectParam: true
|
|
78
99
|
});
|
|
79
100
|
}
|
|
80
|
-
const generateMetaTags = (metaOptions) => {
|
|
81
|
-
if (!metaOptions) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
return Object.keys(metaOptions).map((metaName) => {
|
|
85
|
-
const metaTagContent = metaOptions[metaName];
|
|
86
|
-
return typeof metaTagContent === "string" ? {
|
|
87
|
-
name: metaName,
|
|
88
|
-
content: metaTagContent
|
|
89
|
-
} : metaTagContent;
|
|
90
|
-
}).filter(Boolean);
|
|
91
|
-
};
|
|
92
101
|
async function getMetaTags(entryName, config) {
|
|
93
|
-
|
|
102
|
+
return (0, import_shared.mergeChainedOptions)({
|
|
94
103
|
defaults: {},
|
|
95
104
|
options: config.html.meta,
|
|
96
105
|
utils: { entryName },
|
|
97
106
|
useObjectParam: true
|
|
98
107
|
});
|
|
99
|
-
return generateMetaTags(merged);
|
|
100
108
|
}
|
|
101
109
|
function getTemplateParameters(entryName, config, assetPrefix) {
|
|
102
110
|
return (compilation, assets, assetTags, pluginOptions) => {
|
|
@@ -161,7 +169,7 @@ const applyInjectTags = (api) => {
|
|
|
161
169
|
});
|
|
162
170
|
};
|
|
163
171
|
const pluginHtml = () => ({
|
|
164
|
-
name: "
|
|
172
|
+
name: "rsbuild:html",
|
|
165
173
|
setup(api) {
|
|
166
174
|
api.modifyBundlerChain(
|
|
167
175
|
async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
|
|
@@ -183,31 +191,36 @@ const pluginHtml = () => ({
|
|
|
183
191
|
const chunks = getChunks(entryName, entryValue);
|
|
184
192
|
const inject = getInject(entryName, config);
|
|
185
193
|
const filename = htmlPaths[entryName];
|
|
186
|
-
const
|
|
194
|
+
const { templatePath, templateContent } = await getTemplate(
|
|
195
|
+
entryName,
|
|
196
|
+
config,
|
|
197
|
+
api.context.rootPath
|
|
198
|
+
);
|
|
187
199
|
const templateParameters = getTemplateParameters(
|
|
188
200
|
entryName,
|
|
189
201
|
config,
|
|
190
202
|
assetPrefix
|
|
191
203
|
);
|
|
204
|
+
const metaTags = await getMetaTags(entryName, config);
|
|
192
205
|
const pluginOptions = {
|
|
206
|
+
meta: metaTags,
|
|
193
207
|
chunks,
|
|
194
208
|
inject,
|
|
195
209
|
minify,
|
|
196
210
|
filename,
|
|
197
|
-
template,
|
|
211
|
+
template: templatePath,
|
|
198
212
|
templateParameters,
|
|
199
213
|
scriptLoading: config.html.scriptLoading
|
|
200
214
|
};
|
|
201
215
|
const htmlInfo = {};
|
|
202
216
|
htmlInfoMap[filename] = htmlInfo;
|
|
217
|
+
if (templateContent) {
|
|
218
|
+
htmlInfo.templateContent = templateContent;
|
|
219
|
+
}
|
|
203
220
|
const title = getTitle(entryName, config);
|
|
204
221
|
if (title) {
|
|
205
222
|
htmlInfo.title = title;
|
|
206
223
|
}
|
|
207
|
-
const metaTags = await getMetaTags(entryName, config);
|
|
208
|
-
if (metaTags.length) {
|
|
209
|
-
htmlInfo.meta = metaTags;
|
|
210
|
-
}
|
|
211
224
|
const favicon = getFavicon(entryName, config);
|
|
212
225
|
if (favicon) {
|
|
213
226
|
if ((0, import_shared.isURL)(favicon)) {
|
|
@@ -260,11 +273,10 @@ const pluginHtml = () => ({
|
|
|
260
273
|
// Annotate the CommonJS export names for ESM import in node:
|
|
261
274
|
0 && (module.exports = {
|
|
262
275
|
applyInjectTags,
|
|
263
|
-
generateMetaTags,
|
|
264
276
|
getFavicon,
|
|
265
277
|
getInject,
|
|
266
278
|
getMetaTags,
|
|
267
|
-
|
|
279
|
+
getTemplate,
|
|
268
280
|
getTitle,
|
|
269
281
|
pluginHtml
|
|
270
282
|
});
|
|
@@ -33,7 +33,7 @@ __export(inlineChunk_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(inlineChunk_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
const pluginInlineChunk = () => ({
|
|
36
|
-
name: "
|
|
36
|
+
name: "rsbuild:inline-chunk",
|
|
37
37
|
setup(api) {
|
|
38
38
|
api.modifyBundlerChain(
|
|
39
39
|
async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
|
|
@@ -43,21 +43,17 @@ const pluginInlineChunk = () => ({
|
|
|
43
43
|
}
|
|
44
44
|
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
|
|
45
45
|
const {
|
|
46
|
-
|
|
47
|
-
// todo: not support
|
|
48
|
-
|
|
46
|
+
inlineStyles,
|
|
47
|
+
// todo: not support inlineScripts in Rspack yet, which will take unknown build error
|
|
48
|
+
inlineScripts
|
|
49
49
|
} = config.output;
|
|
50
50
|
const scriptTests = [];
|
|
51
51
|
const styleTests = [];
|
|
52
|
-
if (
|
|
53
|
-
scriptTests.push(
|
|
54
|
-
enableInlineScripts === true ? import_shared.JS_REGEX : enableInlineScripts
|
|
55
|
-
);
|
|
52
|
+
if (inlineScripts) {
|
|
53
|
+
scriptTests.push(inlineScripts === true ? import_shared.JS_REGEX : inlineScripts);
|
|
56
54
|
}
|
|
57
|
-
if (
|
|
58
|
-
styleTests.push(
|
|
59
|
-
enableInlineStyles === true ? import_shared.CSS_REGEX : enableInlineStyles
|
|
60
|
-
);
|
|
55
|
+
if (inlineStyles) {
|
|
56
|
+
styleTests.push(inlineStyles === true ? import_shared.CSS_REGEX : inlineStyles);
|
|
61
57
|
}
|
|
62
58
|
if (!scriptTests.length && !styleTests.length) {
|
|
63
59
|
return;
|
package/dist/plugins/moment.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(nodeAddons_exports);
|
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
const pluginNodeAddons = () => ({
|
|
27
|
-
name: "
|
|
27
|
+
name: "rsbuild:node-addons",
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyBundlerChain(
|
|
30
30
|
async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
|
|
@@ -172,7 +172,7 @@ const SPLIT_STRATEGY_DISPATCHER = {
|
|
|
172
172
|
};
|
|
173
173
|
function pluginSplitChunks() {
|
|
174
174
|
return {
|
|
175
|
-
name: "
|
|
175
|
+
name: "rsbuild:split-chunks",
|
|
176
176
|
setup(api) {
|
|
177
177
|
api.modifyBundlerChain(
|
|
178
178
|
async (chain, { isServer, isWebWorker, isServiceWorker }) => {
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -93,7 +93,7 @@ const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
|
|
|
93
93
|
const openedURLs = [];
|
|
94
94
|
function pluginStartUrl() {
|
|
95
95
|
return {
|
|
96
|
-
name: "
|
|
96
|
+
name: "rsbuild:start-url",
|
|
97
97
|
setup(api) {
|
|
98
98
|
api.onAfterStartDevServer(async (params) => {
|
|
99
99
|
const { port, routes } = params;
|
package/dist/plugins/target.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(target_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(target_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginTarget = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:target",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain(async (chain, { target }) => {
|
|
29
29
|
if (target === "node") {
|
package/dist/plugins/toml.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(toml_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(toml_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginToml = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:toml",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
29
29
|
chain.module.rule(CHAIN_ID.RULE.TOML).type("javascript/auto").test(/\.toml$/).use(CHAIN_ID.USE.TOML).loader((0, import_shared.getSharedPkgCompiledPath)("toml-loader"));
|
package/dist/plugins/wasm.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(wasm_exports);
|
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
const pluginWasm = () => ({
|
|
27
|
-
name: "
|
|
27
|
+
name: "rsbuild:wasm",
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
30
30
|
const config = api.getNormalizedConfig();
|
package/dist/plugins/yaml.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(yaml_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(yaml_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginYaml = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:yaml",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
29
29
|
chain.module.rule(CHAIN_ID.RULE.YAML).type("javascript/auto").test(/\.ya?ml$/).use(CHAIN_ID.USE.YAML).loader((0, import_shared.getSharedPkgCompiledPath)("yaml-loader"));
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
2
|
import type { Compiler } from '@rspack/core';
|
|
3
|
-
import type { MetaAttrs } from '@rsbuild/shared';
|
|
4
3
|
export type HtmlInfo = {
|
|
5
|
-
meta?: MetaAttrs[];
|
|
6
4
|
title?: string;
|
|
7
5
|
favicon?: string;
|
|
6
|
+
templateContent?: string;
|
|
8
7
|
};
|
|
9
8
|
export type HtmlBasicPluginOptions = {
|
|
10
9
|
info: Record<string, HtmlInfo>;
|
|
11
10
|
HtmlPlugin: typeof HtmlWebpackPlugin;
|
|
12
11
|
};
|
|
12
|
+
export declare const hasTitle: (html?: string) => boolean;
|
|
13
13
|
export declare class HtmlBasicPlugin {
|
|
14
14
|
readonly name: string;
|
|
15
15
|
readonly options: HtmlBasicPluginOptions;
|
|
@@ -18,9 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var HtmlBasicPlugin_exports = {};
|
|
20
20
|
__export(HtmlBasicPlugin_exports, {
|
|
21
|
-
HtmlBasicPlugin: () => HtmlBasicPlugin
|
|
21
|
+
HtmlBasicPlugin: () => HtmlBasicPlugin,
|
|
22
|
+
hasTitle: () => hasTitle
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(HtmlBasicPlugin_exports);
|
|
25
|
+
const hasTitle = (html) => html ? /<title/i.test(html) && /<\/title/i.test(html) : false;
|
|
24
26
|
class HtmlBasicPlugin {
|
|
25
27
|
constructor(options) {
|
|
26
28
|
this.name = "HtmlBasicPlugin";
|
|
@@ -40,19 +42,6 @@ class HtmlBasicPlugin {
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
|
-
const addMetaTag = (headTags, outputName) => {
|
|
44
|
-
const { meta } = this.options.info[outputName];
|
|
45
|
-
if (meta) {
|
|
46
|
-
headTags.unshift(
|
|
47
|
-
...meta.map((attr) => ({
|
|
48
|
-
tagName: "meta",
|
|
49
|
-
attributes: attr,
|
|
50
|
-
meta: {},
|
|
51
|
-
voidTag: true
|
|
52
|
-
}))
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
45
|
const addFavicon = (headTags, outputName) => {
|
|
57
46
|
const { favicon } = this.options.info[outputName];
|
|
58
47
|
if (favicon) {
|
|
@@ -72,8 +61,10 @@ class HtmlBasicPlugin {
|
|
|
72
61
|
this.name,
|
|
73
62
|
(data) => {
|
|
74
63
|
const { headTags, outputName } = data;
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
const { templateContent } = this.options.info[outputName];
|
|
65
|
+
if (!hasTitle(templateContent)) {
|
|
66
|
+
addTitleTag(headTags, outputName);
|
|
67
|
+
}
|
|
77
68
|
addFavicon(headTags, outputName);
|
|
78
69
|
return data;
|
|
79
70
|
}
|
|
@@ -83,5 +74,6 @@ class HtmlBasicPlugin {
|
|
|
83
74
|
}
|
|
84
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
85
76
|
0 && (module.exports = {
|
|
86
|
-
HtmlBasicPlugin
|
|
77
|
+
HtmlBasicPlugin,
|
|
78
|
+
hasTitle
|
|
87
79
|
});
|
|
@@ -64,7 +64,7 @@ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputCo
|
|
|
64
64
|
entry: sourceConfig.entry || // TODO: remove sourceConfig.entries in v0.2.0
|
|
65
65
|
// compat with previous config
|
|
66
66
|
sourceConfig.entries || getDefaultEntry(rootPath),
|
|
67
|
-
version: "0.
|
|
67
|
+
version: "0.1.1",
|
|
68
68
|
target,
|
|
69
69
|
rootPath,
|
|
70
70
|
distPath,
|
|
@@ -23,7 +23,7 @@ __export(basic_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(basic_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginBasic = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:basic",
|
|
27
27
|
setup(api) {
|
|
28
28
|
(0, import_shared.applyBasicPlugin)(api);
|
|
29
29
|
}
|
|
@@ -143,7 +143,7 @@ const applyCSSModuleRule = (rules, ruleTest, config) => {
|
|
|
143
143
|
};
|
|
144
144
|
const pluginCss = () => {
|
|
145
145
|
return {
|
|
146
|
-
name: "
|
|
146
|
+
name: "rsbuild:css",
|
|
147
147
|
setup(api) {
|
|
148
148
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
149
149
|
const config = api.getNormalizedConfig();
|
|
@@ -23,7 +23,7 @@ __export(hmr_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(hmr_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginHMR = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:hmr",
|
|
27
27
|
setup(api) {
|
|
28
28
|
api.modifyRspackConfig((rspackConfig, utils) => {
|
|
29
29
|
const config = api.getNormalizedConfig();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(less_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
function pluginLess() {
|
|
36
36
|
return {
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:less",
|
|
38
38
|
setup(api) {
|
|
39
39
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
40
40
|
const config = api.getNormalizedConfig();
|
|
@@ -56,7 +56,7 @@ function applyCSSMinimizer(chain) {
|
|
|
56
56
|
chain.optimization.minimizer(import_shared.CHAIN_ID.MINIMIZER.CSS).use(import_core.SwcCssMinimizerRspackPlugin, []).end();
|
|
57
57
|
}
|
|
58
58
|
const pluginMinimize = () => ({
|
|
59
|
-
name: "
|
|
59
|
+
name: "rsbuild:minimize",
|
|
60
60
|
setup(api) {
|
|
61
61
|
api.modifyBundlerChain((chain, { isProd }) => {
|
|
62
62
|
const config = api.getNormalizedConfig();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(output_exports);
|
|
|
34
34
|
var import_path = require("path");
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
const pluginOutput = () => ({
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:output",
|
|
38
38
|
setup(api) {
|
|
39
39
|
(0, import_shared.applyOutputPlugin)(api);
|
|
40
40
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
@@ -33,7 +33,7 @@ __export(progress_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(progress_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
const pluginProgress = () => ({
|
|
36
|
-
name: "
|
|
36
|
+
name: "rsbuild:progress",
|
|
37
37
|
setup(api) {
|
|
38
38
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
|
|
39
39
|
var _a;
|
|
@@ -23,7 +23,7 @@ __export(resolve_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(resolve_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const pluginResolve = () => ({
|
|
26
|
-
name: "
|
|
26
|
+
name: "rsbuild:resolve",
|
|
27
27
|
setup(api) {
|
|
28
28
|
(0, import_shared.applyResolvePlugin)(api);
|
|
29
29
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
@@ -50,7 +50,7 @@ const stopProfiler = (output, profileSession) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
const pluginRspackProfile = () => ({
|
|
53
|
-
name: "
|
|
53
|
+
name: "rsbuild:rspack-profile",
|
|
54
54
|
setup(api) {
|
|
55
55
|
var _a;
|
|
56
56
|
const RSPACK_PROFILE = (_a = process.env.RSPACK_PROFILE) == null ? void 0 : _a.toUpperCase();
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(sass_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
function pluginSass() {
|
|
36
36
|
return {
|
|
37
|
-
name: "
|
|
37
|
+
name: "rsbuild:sass",
|
|
38
38
|
setup(api) {
|
|
39
39
|
api.onAfterCreateCompiler(({ compiler }) => {
|
|
40
40
|
(0, import_shared.patchCompilerGlobalLocation)(compiler);
|
|
@@ -60,7 +60,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
const pluginSwc = () => ({
|
|
63
|
-
name: "
|
|
63
|
+
name: "rsbuild:swc",
|
|
64
64
|
setup(api) {
|
|
65
65
|
api.modifyBundlerChain(
|
|
66
66
|
async (chain, { CHAIN_ID, target, isServer, isServiceWorker }) => {
|
|
@@ -92,7 +92,7 @@ const pluginSwc = () => ({
|
|
|
92
92
|
swcConfig.env.mode = void 0;
|
|
93
93
|
} else {
|
|
94
94
|
swcConfig.env.mode = polyfillMode;
|
|
95
|
-
await applyCoreJs(swcConfig, chain,
|
|
95
|
+
await applyCoreJs(swcConfig, chain, polyfillMode);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
|
|
@@ -110,7 +110,7 @@ const pluginSwc = () => ({
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
-
async function applyCoreJs(swcConfig, chain,
|
|
113
|
+
async function applyCoreJs(swcConfig, chain, polyfillMode) {
|
|
114
114
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
115
115
|
const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
|
|
116
116
|
const coreJsDir = path.dirname(coreJsPath);
|
|
@@ -121,7 +121,6 @@ async function applyCoreJs(swcConfig, chain, rule, polyfillMode) {
|
|
|
121
121
|
chain.resolve.alias.merge({
|
|
122
122
|
"core-js": coreJsDir
|
|
123
123
|
});
|
|
124
|
-
rule.exclude.add(coreJsDir);
|
|
125
124
|
}
|
|
126
125
|
function applyTransformImport(swcConfig, pluginImport) {
|
|
127
126
|
var _a, _b, _c;
|
|
@@ -21,9 +21,8 @@ __export(transition_exports, {
|
|
|
21
21
|
pluginTransition: () => pluginTransition
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(transition_exports);
|
|
24
|
-
var import_shared = require("@rsbuild/shared");
|
|
25
24
|
const pluginTransition = () => ({
|
|
26
|
-
name: "
|
|
25
|
+
name: "rsbuild:transition",
|
|
27
26
|
setup(api) {
|
|
28
27
|
process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
|
|
29
28
|
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
@@ -31,9 +30,6 @@ const pluginTransition = () => ({
|
|
|
31
30
|
chain.optimization.chunkIds("deterministic");
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
api.modifyRspackConfig((config) => {
|
|
35
|
-
(0, import_shared.setConfig)(config, "experiments.rspackFuture.newResolver", true);
|
|
36
|
-
});
|
|
37
33
|
}
|
|
38
34
|
});
|
|
39
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Server } from 'http';
|
|
3
|
+
import type { Server } from 'http';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import type { DevConfig, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '@rsbuild/shared';
|
|
6
6
|
type Options = {
|
|
7
|
+
publicPaths: string[];
|
|
7
8
|
dev: DevConfig;
|
|
8
9
|
devMiddleware?: CustomDevMiddleware;
|
|
9
10
|
};
|
|
@@ -11,10 +12,12 @@ export default class DevMiddleware extends EventEmitter {
|
|
|
11
12
|
middleware?: DevMiddlewareAPI;
|
|
12
13
|
private devOptions;
|
|
13
14
|
private devMiddleware?;
|
|
15
|
+
private publicPaths;
|
|
14
16
|
private socketServer;
|
|
15
17
|
constructor({
|
|
16
18
|
dev,
|
|
17
|
-
devMiddleware
|
|
19
|
+
devMiddleware,
|
|
20
|
+
publicPaths
|
|
18
21
|
}: Options);
|
|
19
22
|
init(app: Server): void;
|
|
20
23
|
close(): void;
|
|
@@ -44,15 +44,19 @@ function getHMRClientPath(client) {
|
|
|
44
44
|
return clientEntry;
|
|
45
45
|
}
|
|
46
46
|
class DevMiddleware extends import_events.EventEmitter {
|
|
47
|
-
constructor({ dev, devMiddleware }) {
|
|
47
|
+
constructor({ dev, devMiddleware, publicPaths }) {
|
|
48
48
|
super();
|
|
49
49
|
this.devOptions = dev;
|
|
50
|
+
this.publicPaths = publicPaths;
|
|
50
51
|
this.socketServer = new import_socketServer.default(dev);
|
|
51
52
|
this.devMiddleware = devMiddleware;
|
|
52
53
|
}
|
|
53
54
|
init(app) {
|
|
54
55
|
if (this.devMiddleware) {
|
|
55
|
-
this.middleware = this.setupDevMiddleware(
|
|
56
|
+
this.middleware = this.setupDevMiddleware(
|
|
57
|
+
this.devMiddleware,
|
|
58
|
+
this.publicPaths
|
|
59
|
+
);
|
|
56
60
|
}
|
|
57
61
|
app.on("listening", () => {
|
|
58
62
|
this.socketServer.prepare(app);
|
|
@@ -66,7 +70,7 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
66
70
|
sockWrite(type, data) {
|
|
67
71
|
this.socketServer.sockWrite(type, data);
|
|
68
72
|
}
|
|
69
|
-
setupDevMiddleware(devMiddleware) {
|
|
73
|
+
setupDevMiddleware(devMiddleware, publicPaths) {
|
|
70
74
|
const { devOptions } = this;
|
|
71
75
|
const callbacks = {
|
|
72
76
|
onInvalid: () => {
|
|
@@ -80,12 +84,27 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
80
84
|
const enableHMR = this.devOptions.hmr;
|
|
81
85
|
const middleware = devMiddleware({
|
|
82
86
|
headers: devOptions.headers,
|
|
87
|
+
publicPath: "/",
|
|
83
88
|
stats: false,
|
|
84
89
|
callbacks,
|
|
85
90
|
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
86
91
|
serverSideRender: true,
|
|
87
|
-
|
|
92
|
+
writeToDisk: devOptions.writeToDisk
|
|
88
93
|
});
|
|
89
|
-
|
|
94
|
+
const warp = async (req, res, next) => {
|
|
95
|
+
const url = req.url;
|
|
96
|
+
const assetPrefix = url && publicPaths.find((prefix) => url.startsWith(prefix));
|
|
97
|
+
if (assetPrefix && assetPrefix !== "/") {
|
|
98
|
+
req.url = url.slice(assetPrefix.length - 1);
|
|
99
|
+
middleware(req, res, (...args) => {
|
|
100
|
+
req.url = url;
|
|
101
|
+
next(...args);
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
middleware(req, res, next);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
warp.close = middleware.close;
|
|
108
|
+
return warp;
|
|
90
109
|
}
|
|
91
110
|
}
|