@rsbuild/core 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createRsbuild.d.ts +1 -0
- package/dist/createRsbuild.js +14 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/plugins/checkSyntax.d.ts +0 -2
- package/dist/plugins/checkSyntax.js +0 -77
- package/dist/plugins/fileSize.js +4 -7
- package/dist/plugins/html.d.ts +5 -1
- package/dist/plugins/html.js +16 -1
- package/dist/plugins/index.js +0 -1
- package/dist/plugins/startUrl.d.ts +9 -0
- package/dist/plugins/startUrl.js +57 -1
- package/dist/rspack-provider/config/validate/tools.js +0 -4
- package/dist/rspack-provider/core/devMiddleware.d.ts +1 -2
- package/dist/rspack-provider/core/devMiddleware.js +14 -26
- package/dist/rspack-provider/plugins/swc.js +5 -2
- package/dist/rspack-provider/shared/plugin.js +0 -2
- package/dist/rspack-provider/types/rspack.d.ts +1 -0
- package/dist/utils/generateMetaTags.d.ts +11 -0
- package/dist/utils/generateMetaTags.js +64 -0
- package/package.json +4 -5
- package/dist/rspack-provider/plugins/babel.d.ts +0 -12
- package/dist/rspack-provider/plugins/babel.js +0 -130
package/dist/createRsbuild.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type RsbuildInstance, type RsbuildProvider, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildConfig } from './rspack-provider';
|
|
3
|
+
export declare const getCreateRsbuildDefaultOptions: () => Required<CreateRsbuildOptions>;
|
|
3
4
|
export declare function createRsbuild<P extends ({
|
|
4
5
|
rsbuildConfig
|
|
5
6
|
}: {
|
package/dist/createRsbuild.js
CHANGED
|
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var createRsbuild_exports = {};
|
|
30
30
|
__export(createRsbuild_exports, {
|
|
31
|
-
createRsbuild: () => createRsbuild
|
|
31
|
+
createRsbuild: () => createRsbuild,
|
|
32
|
+
getCreateRsbuildDefaultOptions: () => getCreateRsbuildDefaultOptions
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(createRsbuild_exports);
|
|
34
35
|
var import_shared = require("@rsbuild/shared");
|
|
@@ -39,10 +40,19 @@ const getRspackProvider = async (rsbuildConfig) => {
|
|
|
39
40
|
rsbuildConfig
|
|
40
41
|
});
|
|
41
42
|
};
|
|
43
|
+
const getCreateRsbuildDefaultOptions = () => ({
|
|
44
|
+
cwd: process.cwd(),
|
|
45
|
+
entry: {},
|
|
46
|
+
target: ["web"],
|
|
47
|
+
configPath: null
|
|
48
|
+
});
|
|
42
49
|
async function createRsbuild(options) {
|
|
43
50
|
const { rsbuildConfig } = options;
|
|
44
51
|
const provider = options.provider ? options.provider({ rsbuildConfig }) : await getRspackProvider(rsbuildConfig);
|
|
45
|
-
const rsbuildOptions =
|
|
52
|
+
const rsbuildOptions = {
|
|
53
|
+
...getCreateRsbuildDefaultOptions(),
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
46
56
|
const pluginStore = (0, import_shared.createPluginStore)();
|
|
47
57
|
const {
|
|
48
58
|
build,
|
|
@@ -88,5 +98,6 @@ async function createRsbuild(options) {
|
|
|
88
98
|
}
|
|
89
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
100
|
0 && (module.exports = {
|
|
91
|
-
createRsbuild
|
|
101
|
+
createRsbuild,
|
|
102
|
+
getCreateRsbuildDefaultOptions
|
|
92
103
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createRsbuild } from './createRsbuild';
|
|
1
|
+
export { createRsbuild, getCreateRsbuildDefaultOptions } from './createRsbuild';
|
|
2
2
|
export { mergeRsbuildConfig } from '@rsbuild/shared';
|
|
3
3
|
export { defineConfig } from './cli';
|
|
4
4
|
export type { RsbuildPluginAPI, RsbuildConfig } from './rspack-provider';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var src_exports = {};
|
|
|
20
20
|
__export(src_exports, {
|
|
21
21
|
createRsbuild: () => import_createRsbuild.createRsbuild,
|
|
22
22
|
defineConfig: () => import_cli.defineConfig,
|
|
23
|
+
getCreateRsbuildDefaultOptions: () => import_createRsbuild.getCreateRsbuildDefaultOptions,
|
|
23
24
|
mergeRsbuildConfig: () => import_shared.mergeRsbuildConfig
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -30,5 +31,6 @@ var import_cli = require("./cli");
|
|
|
30
31
|
0 && (module.exports = {
|
|
31
32
|
createRsbuild,
|
|
32
33
|
defineConfig,
|
|
34
|
+
getCreateRsbuildDefaultOptions,
|
|
33
35
|
mergeRsbuildConfig
|
|
34
36
|
});
|
|
@@ -1,78 +1 @@
|
|
|
1
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 checkSyntax_exports = {};
|
|
30
|
-
__export(checkSyntax_exports, {
|
|
31
|
-
pluginCheckSyntax: () => pluginCheckSyntax
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(checkSyntax_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
function pluginCheckSyntax() {
|
|
36
|
-
return {
|
|
37
|
-
name: "plugin-check-syntax",
|
|
38
|
-
setup(api) {
|
|
39
|
-
api.modifyBundlerChain(async (chain, { isProd, target }) => {
|
|
40
|
-
const config = api.getNormalizedConfig();
|
|
41
|
-
const { checkSyntax } = config.security;
|
|
42
|
-
if (!isProd || ["node", "web-worker"].includes(target) || !checkSyntax) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const targets = await getCheckTargets(
|
|
46
|
-
api.context,
|
|
47
|
-
config,
|
|
48
|
-
target,
|
|
49
|
-
checkSyntax
|
|
50
|
-
);
|
|
51
|
-
const { CheckSyntaxPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
|
|
52
|
-
chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
|
|
53
|
-
{
|
|
54
|
-
targets,
|
|
55
|
-
rootPath: api.context.rootPath,
|
|
56
|
-
...typeof checkSyntax === "object" ? checkSyntax : {}
|
|
57
|
-
}
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async function getCheckTargets(rsbuildContext, rsbuildConfig, rsbuildTarget, checkSyntax) {
|
|
64
|
-
var _a, _b;
|
|
65
|
-
const browserslist = (_a = await (0, import_shared.getBrowserslistWithDefault)(
|
|
66
|
-
rsbuildContext.rootPath,
|
|
67
|
-
rsbuildConfig,
|
|
68
|
-
rsbuildTarget
|
|
69
|
-
)) != null ? _a : import_shared.DEFAULT_BROWSERSLIST[rsbuildTarget];
|
|
70
|
-
if (checkSyntax === true) {
|
|
71
|
-
return browserslist;
|
|
72
|
-
}
|
|
73
|
-
return (_b = checkSyntax.targets) != null ? _b : browserslist;
|
|
74
|
-
}
|
|
75
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
-
0 && (module.exports = {
|
|
77
|
-
pluginCheckSyntax
|
|
78
|
-
});
|
package/dist/plugins/fileSize.js
CHANGED
|
@@ -38,7 +38,6 @@ var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
39
|
var import_filesize = __toESM(require("filesize"));
|
|
40
40
|
var import_gzip_size = __toESM(require("gzip-size"));
|
|
41
|
-
var import_strip_ansi = __toESM(require("strip-ansi"));
|
|
42
41
|
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
43
42
|
const getAssetColor = (size) => {
|
|
44
43
|
if (size > 300 * 1e3) {
|
|
@@ -98,11 +97,9 @@ async function printFileSizes(stats, distPath) {
|
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
99
|
assets.sort((a, b) => b.size - a.size);
|
|
101
|
-
const longestLabelLength = Math.max(
|
|
102
|
-
...assets.map((a) => (0, import_strip_ansi.default)(a.sizeLabel).length)
|
|
103
|
-
);
|
|
100
|
+
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
104
101
|
const longestFileLength = Math.max(
|
|
105
|
-
...assets.map((a) => (
|
|
102
|
+
...assets.map((a) => (a.folder + import_path.default.sep + a.name).length)
|
|
106
103
|
);
|
|
107
104
|
import_shared.logger.info(`Production file sizes:
|
|
108
105
|
`);
|
|
@@ -112,8 +109,8 @@ async function printFileSizes(stats, distPath) {
|
|
|
112
109
|
assets.forEach((asset) => {
|
|
113
110
|
let { sizeLabel } = asset;
|
|
114
111
|
const { name, folder, gzipSizeLabel } = asset;
|
|
115
|
-
const fileNameLength = (
|
|
116
|
-
const sizeLength =
|
|
112
|
+
const fileNameLength = (folder + import_path.default.sep + name).length;
|
|
113
|
+
const sizeLength = sizeLabel.length;
|
|
117
114
|
totalSize += asset.size;
|
|
118
115
|
totalGzipSize += asset.gzippedSize;
|
|
119
116
|
if (sizeLength < longestLabelLength) {
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { DefaultRsbuildPlugin, SharedRsbuildPluginAPI } from '@rsbuild/shared';
|
|
1
|
+
import type { SharedHtmlConfig, DefaultRsbuildPlugin, SharedRsbuildPluginAPI, NormalizedSharedOutputConfig } from '@rsbuild/shared';
|
|
2
|
+
export declare function getMetaTags(entryName: string, config: {
|
|
3
|
+
html: SharedHtmlConfig;
|
|
4
|
+
output: NormalizedSharedOutputConfig;
|
|
5
|
+
}): Promise<string>;
|
|
2
6
|
export declare const applyInjectTags: (api: SharedRsbuildPluginAPI) => void;
|
|
3
7
|
export declare const pluginHtml: () => DefaultRsbuildPlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var html_exports = {};
|
|
30
30
|
__export(html_exports, {
|
|
31
31
|
applyInjectTags: () => applyInjectTags,
|
|
32
|
+
getMetaTags: () => getMetaTags,
|
|
32
33
|
pluginHtml: () => pluginHtml
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(html_exports);
|
|
@@ -36,9 +37,22 @@ var import_path = __toESM(require("path"));
|
|
|
36
37
|
var import_shared = require("@rsbuild/shared");
|
|
37
38
|
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
38
39
|
var import_lodash = __toESM(require("lodash"));
|
|
40
|
+
var import_generateMetaTags = require("../utils/generateMetaTags");
|
|
41
|
+
async function getMetaTags(entryName, config) {
|
|
42
|
+
var _a;
|
|
43
|
+
const { meta, metaByEntries } = config.html;
|
|
44
|
+
const metaOptions = {
|
|
45
|
+
...meta != null ? meta : {},
|
|
46
|
+
...(_a = metaByEntries == null ? void 0 : metaByEntries[entryName]) != null ? _a : {}
|
|
47
|
+
};
|
|
48
|
+
if (config.output.charset === "utf8") {
|
|
49
|
+
metaOptions.charset = { charset: "utf-8" };
|
|
50
|
+
}
|
|
51
|
+
return (0, import_generateMetaTags.generateMetaTags)(metaOptions);
|
|
52
|
+
}
|
|
39
53
|
async function getTemplateParameters(entryName, config, assetPrefix) {
|
|
40
54
|
const { mountId, templateParameters, templateParametersByEntries } = config.html;
|
|
41
|
-
const meta = await
|
|
55
|
+
const meta = await getMetaTags(entryName, config);
|
|
42
56
|
const title = (0, import_shared.getTitle)(entryName, config);
|
|
43
57
|
const templateParams = (templateParametersByEntries == null ? void 0 : templateParametersByEntries[entryName]) || templateParameters;
|
|
44
58
|
const baseParameters = {
|
|
@@ -214,5 +228,6 @@ const pluginHtml = () => ({
|
|
|
214
228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
229
|
0 && (module.exports = {
|
|
216
230
|
applyInjectTags,
|
|
231
|
+
getMetaTags,
|
|
217
232
|
pluginHtml
|
|
218
233
|
});
|
package/dist/plugins/index.js
CHANGED
|
@@ -51,7 +51,6 @@ const plugins = {
|
|
|
51
51
|
image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("image", import_shared.IMAGE_EXTENSIONS)),
|
|
52
52
|
media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("media", import_shared.MEDIA_EXTENSIONS)),
|
|
53
53
|
assetsRetry: () => Promise.resolve().then(() => __toESM(require("./assetsRetry"))).then((m) => m.pluginAssetsRetry()),
|
|
54
|
-
checkSyntax: () => Promise.resolve().then(() => __toESM(require("./checkSyntax"))).then((m) => m.pluginCheckSyntax()),
|
|
55
54
|
rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
|
|
56
55
|
wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
|
|
57
56
|
moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import { type DefaultRsbuildPlugin } from '@rsbuild/shared';
|
|
2
|
+
/**
|
|
3
|
+
* This method is modified based on source found in
|
|
4
|
+
* https://github.com/facebook/create-react-app
|
|
5
|
+
*
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
8
|
+
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
export declare function openBrowser(url: string): Promise<boolean>;
|
|
2
11
|
export declare const replacePlaceholder: (url: string, port: number) => string;
|
|
3
12
|
export declare function pluginStartUrl(): DefaultRsbuildPlugin;
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -28,12 +28,68 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var startUrl_exports = {};
|
|
30
30
|
__export(startUrl_exports, {
|
|
31
|
+
openBrowser: () => openBrowser,
|
|
31
32
|
pluginStartUrl: () => pluginStartUrl,
|
|
32
33
|
replacePlaceholder: () => replacePlaceholder
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(startUrl_exports);
|
|
35
36
|
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_path = require("path");
|
|
36
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
|
+
var import_child_process = require("child_process");
|
|
40
|
+
const supportedChromiumBrowsers = [
|
|
41
|
+
"Google Chrome Canary",
|
|
42
|
+
"Google Chrome Dev",
|
|
43
|
+
"Google Chrome Beta",
|
|
44
|
+
"Google Chrome",
|
|
45
|
+
"Microsoft Edge",
|
|
46
|
+
"Brave Browser",
|
|
47
|
+
"Vivaldi",
|
|
48
|
+
"Chromium"
|
|
49
|
+
];
|
|
50
|
+
const getTargetBrowser = () => {
|
|
51
|
+
let targetBrowser = process.env.BROWSER;
|
|
52
|
+
if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
|
|
53
|
+
const ps = (0, import_child_process.execSync)("ps cax").toString();
|
|
54
|
+
targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
|
|
55
|
+
}
|
|
56
|
+
return targetBrowser;
|
|
57
|
+
};
|
|
58
|
+
async function openBrowser(url) {
|
|
59
|
+
const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
|
|
60
|
+
if (shouldTryOpenChromeWithAppleScript) {
|
|
61
|
+
try {
|
|
62
|
+
const targetBrowser = getTargetBrowser();
|
|
63
|
+
if (targetBrowser) {
|
|
64
|
+
(0, import_child_process.execSync)(
|
|
65
|
+
`osascript openChrome.applescript "${encodeURI(
|
|
66
|
+
url
|
|
67
|
+
)}" "${targetBrowser}"`,
|
|
68
|
+
{
|
|
69
|
+
stdio: "ignore",
|
|
70
|
+
cwd: (0, import_path.join)(__dirname, "../../static")
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
import_shared.logger.error(
|
|
78
|
+
"Failed to open start URL with apple script:",
|
|
79
|
+
JSON.stringify(err)
|
|
80
|
+
);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const { default: open } = await Promise.resolve().then(() => __toESM(require("open")));
|
|
86
|
+
await open(url);
|
|
87
|
+
return true;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
import_shared.logger.error("Failed to open start URL:", JSON.stringify(err));
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
37
93
|
const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
|
|
38
94
|
const openedURLs = [];
|
|
39
95
|
function pluginStartUrl() {
|
|
@@ -65,7 +121,6 @@ function pluginStartUrl() {
|
|
|
65
121
|
)
|
|
66
122
|
);
|
|
67
123
|
}
|
|
68
|
-
const { openBrowser } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
|
|
69
124
|
const openUrls = () => {
|
|
70
125
|
for (const url of urls) {
|
|
71
126
|
if (!openedURLs.includes(url)) {
|
|
@@ -87,6 +142,7 @@ function pluginStartUrl() {
|
|
|
87
142
|
}
|
|
88
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
144
|
0 && (module.exports = {
|
|
145
|
+
openBrowser,
|
|
90
146
|
pluginStartUrl,
|
|
91
147
|
replacePlaceholder
|
|
92
148
|
});
|
|
@@ -23,14 +23,10 @@ __export(tools_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(tools_exports);
|
|
24
24
|
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const toolsConfigSchema = import_shared.sharedToolsConfigSchema.extend({
|
|
26
|
-
sass: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addExcludes: import_shared.FileFilterUtilSchema })),
|
|
27
|
-
less: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addExcludes: import_shared.FileFilterUtilSchema })),
|
|
28
26
|
htmlPlugin: import_shared.z.chained(
|
|
29
27
|
import_shared.z.any(),
|
|
30
28
|
import_shared.z.object({ entryName: import_shared.z.string(), entryValue: import_shared.z.any() })
|
|
31
29
|
),
|
|
32
|
-
postcss: import_shared.z.chained(import_shared.z.any(), import_shared.z.object({ addPlugins: import_shared.z.function() })),
|
|
33
|
-
autoprefixer: import_shared.z.chained(import_shared.z.any()),
|
|
34
30
|
rspack: import_shared.z.chained(import_shared.z.any(), import_shared.z.any())
|
|
35
31
|
});
|
|
36
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ModernDevServerOptions } from '@modern-js/server';
|
|
2
2
|
import type { Compiler, MultiCompiler } from '@rspack/core';
|
|
3
3
|
type DevMiddlewareOptions = ModernDevServerOptions['devMiddleware'];
|
|
4
|
-
export declare
|
|
5
|
-
export declare const getDevMiddleware: (compiler: Compiler | MultiCompiler) => NonNullable<DevMiddlewareOptions>;
|
|
4
|
+
export declare const getDevMiddleware: (multiCompiler: Compiler | MultiCompiler) => NonNullable<DevMiddlewareOptions>;
|
|
6
5
|
export {};
|
|
@@ -28,50 +28,38 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var devMiddleware_exports = {};
|
|
30
30
|
__export(devMiddleware_exports, {
|
|
31
|
-
getDevMiddleware: () => getDevMiddleware
|
|
32
|
-
getHotRuntimeEntries: () => getHotRuntimeEntries
|
|
31
|
+
getDevMiddleware: () => getDevMiddleware
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(devMiddleware_exports);
|
|
35
34
|
var import_webpack_dev_middleware = __toESM(require("@rsbuild/shared/webpack-dev-middleware"));
|
|
36
35
|
var import_shared = require("@rsbuild/shared");
|
|
37
|
-
function getHotRuntimeEntries(compiler) {
|
|
38
|
-
var _a, _b, _c, _d, _e;
|
|
39
|
-
const hot = (_b = (_a = compiler.options.devServer) == null ? void 0 : _a.hot) != null ? _b : true;
|
|
40
|
-
const refresh = (_e = (_d = (_c = compiler.options.builtins) == null ? void 0 : _c.react) == null ? void 0 : _d.refresh) != null ? _e : true;
|
|
41
|
-
if (hot && refresh) {
|
|
42
|
-
const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh-entry");
|
|
43
|
-
return [reactRefreshEntryPath];
|
|
44
|
-
}
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
36
|
function applyHMREntry(compiler, clientPath) {
|
|
48
37
|
if (!(0, import_shared.isClientCompiler)(compiler)) {
|
|
49
38
|
return;
|
|
50
39
|
}
|
|
51
|
-
const hotRuntimeEntires = getHotRuntimeEntries(compiler);
|
|
52
|
-
const entires = [...hotRuntimeEntires, clientPath];
|
|
53
40
|
for (const key in compiler.options.entry) {
|
|
54
41
|
compiler.options.entry[key].import = [
|
|
55
|
-
|
|
42
|
+
clientPath,
|
|
56
43
|
...compiler.options.entry[key].import || []
|
|
57
44
|
];
|
|
58
45
|
}
|
|
59
46
|
}
|
|
60
|
-
const getDevMiddleware = (
|
|
47
|
+
const getDevMiddleware = (multiCompiler) => (options) => {
|
|
61
48
|
const { hmrClientPath, callbacks, ...restOptions } = options;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
hmrClientPath && applyHMREntry(compiler, hmrClientPath);
|
|
49
|
+
const setupCompiler = (compiler) => {
|
|
50
|
+
if (hmrClientPath) {
|
|
51
|
+
applyHMREntry(compiler, hmrClientPath);
|
|
52
|
+
}
|
|
69
53
|
(0, import_shared.setupServerHooks)(compiler, callbacks);
|
|
54
|
+
};
|
|
55
|
+
if (multiCompiler.compilers) {
|
|
56
|
+
multiCompiler.compilers.forEach(setupCompiler);
|
|
57
|
+
} else {
|
|
58
|
+
setupCompiler(multiCompiler);
|
|
70
59
|
}
|
|
71
|
-
return (0, import_webpack_dev_middleware.default)(
|
|
60
|
+
return (0, import_webpack_dev_middleware.default)(multiCompiler, restOptions);
|
|
72
61
|
};
|
|
73
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
63
|
0 && (module.exports = {
|
|
75
|
-
getDevMiddleware
|
|
76
|
-
getHotRuntimeEntries
|
|
64
|
+
getDevMiddleware
|
|
77
65
|
});
|
|
@@ -94,7 +94,7 @@ const pluginSwc = () => ({
|
|
|
94
94
|
swcConfig.env.mode = void 0;
|
|
95
95
|
} else {
|
|
96
96
|
swcConfig.env.mode = polyfillMode;
|
|
97
|
-
await applyCoreJs(swcConfig, chain, rule);
|
|
97
|
+
await applyCoreJs(swcConfig, chain, rule, polyfillMode);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
rule.use(CHAIN_ID.USE.SWC).loader(builtinSwcLoaderName).options(swcConfig);
|
|
@@ -114,11 +114,14 @@ const pluginSwc = () => ({
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
async function applyCoreJs(swcConfig, chain, rule) {
|
|
117
|
+
async function applyCoreJs(swcConfig, chain, rule, polyfillMode) {
|
|
118
118
|
const coreJsPath = require.resolve("core-js/package.json");
|
|
119
119
|
const version = (0, import_shared.getCoreJsVersion)(coreJsPath);
|
|
120
120
|
const coreJsDir = path.dirname(coreJsPath);
|
|
121
121
|
swcConfig.env.coreJs = version;
|
|
122
|
+
if (polyfillMode === "usage") {
|
|
123
|
+
swcConfig.env.shippedProposals = true;
|
|
124
|
+
}
|
|
122
125
|
chain.resolve.alias.merge({
|
|
123
126
|
"core-js": coreJsDir
|
|
124
127
|
});
|
|
@@ -54,7 +54,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
54
54
|
plugins.nodeAddons(),
|
|
55
55
|
// pug plugin should after html plugin
|
|
56
56
|
Promise.resolve().then(() => __toESM(require("../plugins/pug"))).then((m) => m.pluginPug()),
|
|
57
|
-
Promise.resolve().then(() => __toESM(require("../plugins/babel"))).then((m) => m.pluginBabel()),
|
|
58
57
|
plugins.define(),
|
|
59
58
|
Promise.resolve().then(() => __toESM(require("../plugins/css"))).then((m) => m.pluginCss()),
|
|
60
59
|
Promise.resolve().then(() => __toESM(require("../plugins/less"))).then((m) => m.pluginLess()),
|
|
@@ -73,7 +72,6 @@ const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
|
73
72
|
plugins.inlineChunk(),
|
|
74
73
|
plugins.bundleAnalyzer(),
|
|
75
74
|
plugins.assetsRetry(),
|
|
76
|
-
plugins.checkSyntax(),
|
|
77
75
|
plugins.networkPerformance(),
|
|
78
76
|
plugins.preloadOrPrefetch(),
|
|
79
77
|
plugins.performance(),
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright JS Foundation and other contributors.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file at
|
|
6
|
+
* https://github.com/jantimon/html-webpack-plugin/blob/main/LICENSE
|
|
7
|
+
*
|
|
8
|
+
* Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
|
|
9
|
+
*/
|
|
10
|
+
import type { MetaOptions } from '@rsbuild/shared';
|
|
11
|
+
export declare const generateMetaTags: (metaOptions?: MetaOptions) => string;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 generateMetaTags_exports = {};
|
|
20
|
+
__export(generateMetaTags_exports, {
|
|
21
|
+
generateMetaTags: () => generateMetaTags
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(generateMetaTags_exports);
|
|
24
|
+
const tagObjectToString = (tagDefinition) => {
|
|
25
|
+
const attributes = Object.keys(tagDefinition.attributes || {}).filter(
|
|
26
|
+
(attributeName) => tagDefinition.attributes[attributeName] !== false
|
|
27
|
+
).map((attributeName) => {
|
|
28
|
+
if (tagDefinition.attributes[attributeName] === true) {
|
|
29
|
+
return attributeName;
|
|
30
|
+
}
|
|
31
|
+
return `${attributeName}="${tagDefinition.attributes[attributeName]}"`;
|
|
32
|
+
});
|
|
33
|
+
return `<${[tagDefinition.tagName].concat(attributes).join(" ")}>${tagDefinition.innerHTML || ""}${tagDefinition.voidTag ? "" : `</${tagDefinition.tagName}>`}`;
|
|
34
|
+
};
|
|
35
|
+
const generateMetaTags = (metaOptions) => {
|
|
36
|
+
if (!metaOptions) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const metaTagAttributeObjects = Object.keys(metaOptions).map((metaName) => {
|
|
40
|
+
const metaTagContent = metaOptions[metaName];
|
|
41
|
+
return typeof metaTagContent === "string" ? {
|
|
42
|
+
name: metaName,
|
|
43
|
+
content: metaTagContent
|
|
44
|
+
} : metaTagContent;
|
|
45
|
+
}).filter((attribute) => attribute !== false);
|
|
46
|
+
return metaTagAttributeObjects.map((metaTagAttributes) => {
|
|
47
|
+
if (metaTagAttributes === false) {
|
|
48
|
+
throw new Error("Invalid meta tag");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
tagName: "meta",
|
|
52
|
+
voidTag: true,
|
|
53
|
+
attributes: metaTagAttributes
|
|
54
|
+
};
|
|
55
|
+
}).reduce(
|
|
56
|
+
(memo, tagObject) => `${memo}
|
|
57
|
+
${tagObjectToString(tagObject)}`,
|
|
58
|
+
""
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
generateMetaTags
|
|
64
|
+
});
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"node": ">=14.0.0"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"version": "0.0.
|
|
20
|
+
"version": "0.0.11",
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -68,22 +68,21 @@
|
|
|
68
68
|
"provenance": true
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@modern-js/server": "^2.
|
|
71
|
+
"@modern-js/server": "^2.39.0",
|
|
72
72
|
"@rspack/core": "0.3.8",
|
|
73
|
-
"@rspack/dev-client": "0.3.8",
|
|
74
73
|
"@rspack/plugin-html": "0.3.8",
|
|
75
74
|
"commander": "^10.0.1",
|
|
76
75
|
"filesize": "^8.0.7",
|
|
77
76
|
"gzip-size": "^6.0.0",
|
|
78
77
|
"jiti": "^1.20.0",
|
|
79
78
|
"lodash": "^4.17.21",
|
|
79
|
+
"open": "^8.4.0",
|
|
80
80
|
"pkg-up": "^3.1.0",
|
|
81
81
|
"postcss": "8.4.31",
|
|
82
82
|
"rspack-manifest-plugin": "5.0.0-alpha0",
|
|
83
83
|
"semver": "^7.5.4",
|
|
84
|
-
"strip-ansi": "^6.0.1",
|
|
85
84
|
"webpack": "^5.88.1",
|
|
86
|
-
"@rsbuild/shared": "0.0.
|
|
85
|
+
"@rsbuild/shared": "0.0.11"
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
89
88
|
"@types/lodash": "^4.14.200",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* The `@babel/preset-typescript` default options.
|
|
4
|
-
*/
|
|
5
|
-
export declare const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: {
|
|
6
|
-
allowNamespaces: boolean;
|
|
7
|
-
allExtensions: boolean;
|
|
8
|
-
allowDeclareFields: boolean;
|
|
9
|
-
optimizeConstEnums: boolean;
|
|
10
|
-
isTSX: boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare const pluginBabel: () => RsbuildPlugin;
|
|
@@ -1,130 +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 babel_exports = {};
|
|
30
|
-
__export(babel_exports, {
|
|
31
|
-
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: () => DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS,
|
|
32
|
-
pluginBabel: () => pluginBabel
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(babel_exports);
|
|
35
|
-
var import_shared = require("@rsbuild/shared");
|
|
36
|
-
var import_lodash = require("lodash");
|
|
37
|
-
const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
|
38
|
-
allowNamespaces: true,
|
|
39
|
-
allExtensions: true,
|
|
40
|
-
allowDeclareFields: true,
|
|
41
|
-
// aligns Babel's behavior with TypeScript's default behavior.
|
|
42
|
-
// https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
|
|
43
|
-
optimizeConstEnums: true,
|
|
44
|
-
isTSX: true
|
|
45
|
-
};
|
|
46
|
-
const pluginBabel = () => ({
|
|
47
|
-
name: "plugin-babel",
|
|
48
|
-
pre: ["plugin-swc"],
|
|
49
|
-
setup(api) {
|
|
50
|
-
api.modifyBundlerChain(
|
|
51
|
-
async (chain, { CHAIN_ID, isProd, getCompiledPath }) => {
|
|
52
|
-
const config = api.getNormalizedConfig();
|
|
53
|
-
if (!config.tools.babel) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const getBabelOptions = (config2) => {
|
|
57
|
-
const includes2 = [];
|
|
58
|
-
const excludes2 = [];
|
|
59
|
-
const babelUtils = {
|
|
60
|
-
addIncludes(items) {
|
|
61
|
-
if (Array.isArray(items)) {
|
|
62
|
-
includes2.push(...items);
|
|
63
|
-
} else {
|
|
64
|
-
includes2.push(items);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
addExcludes(items) {
|
|
68
|
-
if (Array.isArray(items)) {
|
|
69
|
-
excludes2.push(...items);
|
|
70
|
-
} else {
|
|
71
|
-
excludes2.push(items);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const baseConfig = {
|
|
76
|
-
plugins: [],
|
|
77
|
-
presets: [
|
|
78
|
-
// TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
|
|
79
|
-
[
|
|
80
|
-
require.resolve("@babel/preset-typescript"),
|
|
81
|
-
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
82
|
-
]
|
|
83
|
-
]
|
|
84
|
-
};
|
|
85
|
-
const userBabelConfig = (0, import_shared.applyUserBabelConfig)(
|
|
86
|
-
(0, import_lodash.cloneDeep)(baseConfig),
|
|
87
|
-
config2.tools.babel,
|
|
88
|
-
babelUtils
|
|
89
|
-
);
|
|
90
|
-
const notModify = (0, import_lodash.isEqual)(baseConfig, userBabelConfig) && !(includes2 == null ? void 0 : includes2.length) && !(excludes2 == null ? void 0 : excludes2.length);
|
|
91
|
-
if (notModify) {
|
|
92
|
-
return {};
|
|
93
|
-
}
|
|
94
|
-
const babelOptions2 = {
|
|
95
|
-
babelrc: false,
|
|
96
|
-
configFile: false,
|
|
97
|
-
compact: isProd,
|
|
98
|
-
...userBabelConfig
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
babelOptions: babelOptions2,
|
|
102
|
-
includes: includes2,
|
|
103
|
-
excludes: excludes2
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const {
|
|
107
|
-
babelOptions,
|
|
108
|
-
includes = [],
|
|
109
|
-
excludes = []
|
|
110
|
-
} = getBabelOptions(config);
|
|
111
|
-
if (!babelOptions) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
115
|
-
includes.forEach((condition) => {
|
|
116
|
-
rule.include.add(condition);
|
|
117
|
-
});
|
|
118
|
-
excludes.forEach((condition) => {
|
|
119
|
-
rule.exclude.add(condition);
|
|
120
|
-
});
|
|
121
|
-
rule.test((0, import_shared.mergeRegex)(import_shared.JS_REGEX, import_shared.TS_REGEX)).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(getCompiledPath("babel-loader")).options(babelOptions);
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
-
0 && (module.exports = {
|
|
128
|
-
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS,
|
|
129
|
-
pluginBabel
|
|
130
|
-
});
|