@rsbuild/core 0.1.1 → 0.1.3
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/ws/index.d.ts +410 -0
- package/compiled/ws/index.js +1 -0
- package/compiled/ws/license +20 -0
- package/compiled/ws/package.json +1 -0
- package/dist/cli/commands.d.ts +6 -3
- package/dist/cli/commands.js +15 -11
- package/dist/cli/config.d.ts +13 -2
- package/dist/cli/config.js +29 -19
- package/dist/cli/prepare.js +1 -1
- package/dist/client/hmr.js +4 -4
- package/dist/createRsbuild.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/plugins/fileSize.js +43 -23
- package/dist/plugins/html.d.ts +1 -1
- package/dist/plugins/html.js +10 -3
- package/dist/plugins/nodeAddons.js +1 -1
- package/dist/plugins/performance.js +3 -4
- package/dist/plugins/splitChunks.js +3 -5
- package/dist/plugins/startUrl.js +6 -4
- package/dist/rspack-provider/core/build.js +3 -3
- package/dist/rspack-provider/core/createCompiler.d.ts +1 -1
- package/dist/rspack-provider/core/createCompiler.js +16 -0
- package/dist/rspack-provider/core/createContext.js +1 -1
- package/dist/rspack-provider/core/initConfigs.d.ts +4 -0
- package/dist/rspack-provider/core/initConfigs.js +16 -5
- package/dist/rspack-provider/core/initHooks.d.ts +4 -3
- package/dist/rspack-provider/core/initHooks.js +2 -0
- package/dist/rspack-provider/core/initPlugins.js +2 -0
- package/dist/rspack-provider/core/inspectConfig.d.ts +12 -1
- package/dist/rspack-provider/core/inspectConfig.js +6 -2
- package/dist/rspack-provider/core/rspackConfig.js +9 -4
- package/dist/rspack-provider/index.d.ts +2 -1
- package/dist/rspack-provider/index.js +5 -4
- package/dist/rspack-provider/plugins/css.js +1 -2
- package/dist/rspack-provider/plugins/less.js +1 -2
- package/dist/rspack-provider/plugins/progress.js +2 -5
- package/dist/rspack-provider/plugins/rspackProfile.js +1 -2
- package/dist/rspack-provider/plugins/sass.js +1 -2
- package/dist/rspack-provider/plugins/swc.js +5 -5
- package/dist/rspack-provider/provider.d.ts +2 -2
- package/dist/rspack-provider/provider.js +2 -7
- package/dist/rspack-provider/shared.d.ts +2 -2
- package/dist/rspack-provider/shared.js +8 -9
- package/dist/server/dev-middleware/index.js +5 -6
- package/dist/server/dev-middleware/socketServer.d.ts +3 -3
- package/dist/server/dev-middleware/socketServer.js +2 -3
- package/dist/server/devServer.d.ts +3 -3
- package/dist/server/devServer.js +6 -9
- package/dist/server/middlewares.js +1 -2
- package/dist/server/prodServer.d.ts +3 -2
- package/dist/server/prodServer.js +14 -11
- package/dist/server/proxy.js +1 -2
- package/dist/types.d.ts +2 -2
- package/package.json +2 -4
package/dist/cli/config.d.ts
CHANGED
|
@@ -5,5 +5,16 @@ export type RsbuildConfig = BaseRsbuildConfig & {
|
|
|
5
5
|
*/
|
|
6
6
|
provider?: any;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
export type ConfigParams = {
|
|
9
|
+
env: string;
|
|
10
|
+
command: string;
|
|
11
|
+
};
|
|
12
|
+
export type RsbuildConfigFn = (env: ConfigParams) => RsbuildConfig | Promise<RsbuildConfig>;
|
|
13
|
+
export type RsbuildConfigExport = RsbuildConfig | RsbuildConfigFn;
|
|
14
|
+
/**
|
|
15
|
+
* This function helps you to autocomplete configuration types.
|
|
16
|
+
* It accepts a Rsbuild config object, or a function that returns a config.
|
|
17
|
+
*/
|
|
18
|
+
export declare function defineConfig(config: RsbuildConfig): RsbuildConfig;
|
|
19
|
+
export declare function defineConfig(config: RsbuildConfigFn): RsbuildConfigFn;
|
|
20
|
+
export declare function loadConfig(customConfig?: string): Promise<RsbuildConfig>;
|
package/dist/cli/config.js
CHANGED
|
@@ -36,7 +36,9 @@ var import_fs = __toESM(require("fs"));
|
|
|
36
36
|
var import_path = require("path");
|
|
37
37
|
var import_shared = require("@rsbuild/shared");
|
|
38
38
|
var import_restart = require("../server/restart");
|
|
39
|
-
|
|
39
|
+
function defineConfig(config) {
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
40
42
|
const resolveConfigPath = (customConfig) => {
|
|
41
43
|
const root = process.cwd();
|
|
42
44
|
if (customConfig) {
|
|
@@ -82,26 +84,34 @@ async function watchConfig(configFile) {
|
|
|
82
84
|
}
|
|
83
85
|
async function loadConfig(customConfig) {
|
|
84
86
|
const configFile = resolveConfigPath(customConfig);
|
|
85
|
-
if (configFile) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
87
|
+
if (!configFile) {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const { default: jiti } = await Promise.resolve().then(() => __toESM(require("../../compiled/jiti")));
|
|
92
|
+
const loadConfig2 = jiti(__filename, {
|
|
93
|
+
esmResolve: true,
|
|
94
|
+
// disable require cache to support restart CLI and read the new config
|
|
95
|
+
requireCache: false,
|
|
96
|
+
interopDefault: true
|
|
97
|
+
});
|
|
98
|
+
const command = process.argv[2];
|
|
99
|
+
if (command === "dev") {
|
|
100
|
+
watchConfig(configFile);
|
|
101
|
+
}
|
|
102
|
+
const configExport = loadConfig2(configFile);
|
|
103
|
+
if (typeof configExport === "function") {
|
|
104
|
+
const params = {
|
|
105
|
+
env: process.env.NODE_ENV,
|
|
106
|
+
command
|
|
107
|
+
};
|
|
108
|
+
return await configExport(params) || {};
|
|
102
109
|
}
|
|
110
|
+
return configExport;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
import_shared.logger.error(`Failed to load file: ${import_shared.color.dim(configFile)}`);
|
|
113
|
+
throw err;
|
|
103
114
|
}
|
|
104
|
-
return {};
|
|
105
115
|
}
|
|
106
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
117
|
0 && (module.exports = {
|
package/dist/cli/prepare.js
CHANGED
|
@@ -34,7 +34,7 @@ function prepareCli() {
|
|
|
34
34
|
if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
|
|
35
35
|
console.log();
|
|
36
36
|
}
|
|
37
|
-
import_rslog.logger.greet(` ${`Rsbuild v${"0.1.
|
|
37
|
+
import_rslog.logger.greet(` ${`Rsbuild v${"0.1.3"}`}
|
|
38
38
|
`);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/client/hmr.js
CHANGED
|
@@ -198,15 +198,15 @@ var require_formatStats = __commonJS({
|
|
|
198
198
|
return message.trim();
|
|
199
199
|
}
|
|
200
200
|
function formatStatsMessages2(json) {
|
|
201
|
-
var
|
|
202
|
-
var formattedErrors =
|
|
203
|
-
var formattedWarnings =
|
|
201
|
+
var _json_errors, _json_warnings, _result_errors;
|
|
202
|
+
var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
|
203
|
+
var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
|
204
204
|
var result = {
|
|
205
205
|
errors: formattedErrors || [],
|
|
206
206
|
warnings: formattedWarnings || [],
|
|
207
207
|
errorTips: []
|
|
208
208
|
};
|
|
209
|
-
if ((
|
|
209
|
+
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
|
210
210
|
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
211
211
|
}
|
|
212
212
|
if (result.errors.length > 1) {
|
package/dist/createRsbuild.js
CHANGED
|
@@ -72,9 +72,11 @@ async function createRsbuild(options) {
|
|
|
72
72
|
"onBeforeBuild",
|
|
73
73
|
"onBeforeCreateCompiler",
|
|
74
74
|
"onBeforeStartDevServer",
|
|
75
|
+
"onBeforeStartProdServer",
|
|
75
76
|
"onAfterBuild",
|
|
76
77
|
"onAfterCreateCompiler",
|
|
77
78
|
"onAfterStartDevServer",
|
|
79
|
+
"onAfterStartProdServer",
|
|
78
80
|
"onDevCompileDone",
|
|
79
81
|
"onExit",
|
|
80
82
|
"getHTMLPaths",
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { mergeRsbuildConfig } from '@rsbuild/shared';
|
|
|
7
7
|
export { defineConfig } from './cli/config';
|
|
8
8
|
export type { Rspack } from './rspack-provider';
|
|
9
9
|
export type { RsbuildConfig, NormalizedConfig, RsbuildPlugin, RsbuildPluginAPI } from './types';
|
|
10
|
-
export type { Context as RsbuildContext, RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn } from '@rsbuild/shared';
|
|
10
|
+
export type { Context as RsbuildContext, RsbuildMode, RsbuildEntry, RsbuildTarget, RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn } from '@rsbuild/shared';
|
package/dist/plugins/fileSize.js
CHANGED
|
@@ -61,7 +61,10 @@ const calcFileSize = (len) => {
|
|
|
61
61
|
const val = len / 1e3;
|
|
62
62
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
63
63
|
};
|
|
64
|
-
async function printFileSizes(stats, distPath) {
|
|
64
|
+
async function printFileSizes(config, stats, distPath) {
|
|
65
|
+
if (config.detail === false && config.total === false) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
65
68
|
const { default: gzipSize } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/gzip-size")));
|
|
66
69
|
const formatAsset = (asset) => {
|
|
67
70
|
const fileName = asset.name.split("?")[0];
|
|
@@ -98,13 +101,15 @@ async function printFileSizes(stats, distPath) {
|
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
103
|
assets.sort((a, b) => b.size - a.size);
|
|
104
|
+
import_shared2.logger.info(`Production file sizes:
|
|
105
|
+
`);
|
|
101
106
|
const longestLabelLength = Math.max(...assets.map((a) => a.sizeLabel.length));
|
|
102
107
|
const longestFileLength = Math.max(
|
|
103
108
|
...assets.map((a) => (a.folder + import_path.default.sep + a.name).length)
|
|
104
109
|
);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
if (config.detail !== false) {
|
|
111
|
+
printHeader(longestFileLength, longestLabelLength);
|
|
112
|
+
}
|
|
108
113
|
let totalSize = 0;
|
|
109
114
|
let totalGzipSize = 0;
|
|
110
115
|
assets.forEach((asset) => {
|
|
@@ -114,36 +119,51 @@ async function printFileSizes(stats, distPath) {
|
|
|
114
119
|
const sizeLength = sizeLabel.length;
|
|
115
120
|
totalSize += asset.size;
|
|
116
121
|
totalGzipSize += asset.gzippedSize;
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
if (config.detail !== false) {
|
|
123
|
+
if (sizeLength < longestLabelLength) {
|
|
124
|
+
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
125
|
+
sizeLabel += rightPadding;
|
|
126
|
+
}
|
|
127
|
+
let fileNameLabel = import_shared2.color.dim(asset.folder + import_path.default.sep) + import_shared2.color.cyan(asset.name);
|
|
128
|
+
if (fileNameLength < longestFileLength) {
|
|
129
|
+
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
130
|
+
fileNameLabel += rightPadding;
|
|
131
|
+
}
|
|
132
|
+
import_shared2.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
125
133
|
}
|
|
126
|
-
import_shared2.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
127
134
|
});
|
|
128
|
-
|
|
129
|
-
import_shared2.color.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
import_shared2.color.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
if (config.total !== false) {
|
|
136
|
+
const totalSizeLabel = `${import_shared2.color.bold(
|
|
137
|
+
import_shared2.color.blue("Total size:")
|
|
138
|
+
)} ${calcFileSize(totalSize)}`;
|
|
139
|
+
const gzippedSizeLabel = `${import_shared2.color.bold(
|
|
140
|
+
import_shared2.color.blue("Gzipped size:")
|
|
141
|
+
)} ${calcFileSize(totalGzipSize)}`;
|
|
142
|
+
import_shared2.logger.log(`
|
|
135
143
|
${totalSizeLabel}
|
|
136
144
|
${gzippedSizeLabel}
|
|
137
145
|
`);
|
|
146
|
+
}
|
|
138
147
|
}
|
|
139
148
|
const pluginFileSize = () => ({
|
|
140
149
|
name: "rsbuild:file-size",
|
|
141
150
|
setup(api) {
|
|
142
151
|
api.onAfterBuild(async ({ stats }) => {
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
152
|
+
const { printFileSize } = api.getNormalizedConfig().performance;
|
|
153
|
+
if (printFileSize === false) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const printFileSizeConfig = typeof printFileSize === "boolean" ? {
|
|
157
|
+
total: true,
|
|
158
|
+
detail: true
|
|
159
|
+
} : printFileSize;
|
|
160
|
+
if (stats) {
|
|
145
161
|
try {
|
|
146
|
-
await printFileSizes(
|
|
162
|
+
await printFileSizes(
|
|
163
|
+
printFileSizeConfig,
|
|
164
|
+
stats,
|
|
165
|
+
api.context.distPath
|
|
166
|
+
);
|
|
147
167
|
} catch (err) {
|
|
148
168
|
import_shared2.logger.warn("Failed to print file size.");
|
|
149
169
|
import_shared2.logger.warn(err);
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -12,6 +12,6 @@ export declare function getFavicon(entryName: string, config: {
|
|
|
12
12
|
export declare function getMetaTags(entryName: string, config: {
|
|
13
13
|
html: HtmlConfig;
|
|
14
14
|
output: NormalizedOutputConfig;
|
|
15
|
-
}):
|
|
15
|
+
}, templateContent?: string): import("@rsbuild/shared").MetaOptions;
|
|
16
16
|
export declare const applyInjectTags: (api: SharedRsbuildPluginAPI) => void;
|
|
17
17
|
export declare const pluginHtml: () => RsbuildPlugin;
|
package/dist/plugins/html.js
CHANGED
|
@@ -98,13 +98,20 @@ function getFavicon(entryName, config) {
|
|
|
98
98
|
useObjectParam: true
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
function getMetaTags(entryName, config, templateContent) {
|
|
102
|
+
const metaTags = (0, import_shared.mergeChainedOptions)({
|
|
103
103
|
defaults: {},
|
|
104
104
|
options: config.html.meta,
|
|
105
105
|
utils: { entryName },
|
|
106
106
|
useObjectParam: true
|
|
107
107
|
});
|
|
108
|
+
if (templateContent && metaTags.charset) {
|
|
109
|
+
const charsetRegExp = /<meta[^>]+charset=["'][^>]*>/i;
|
|
110
|
+
if (charsetRegExp.test(templateContent)) {
|
|
111
|
+
delete metaTags.charset;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return metaTags;
|
|
108
115
|
}
|
|
109
116
|
function getTemplateParameters(entryName, config, assetPrefix) {
|
|
110
117
|
return (compilation, assets, assetTags, pluginOptions) => {
|
|
@@ -201,7 +208,7 @@ const pluginHtml = () => ({
|
|
|
201
208
|
config,
|
|
202
209
|
assetPrefix
|
|
203
210
|
);
|
|
204
|
-
const metaTags =
|
|
211
|
+
const metaTags = getMetaTags(entryName, config, templateContent);
|
|
205
212
|
const pluginOptions = {
|
|
206
213
|
meta: metaTags,
|
|
207
214
|
chunks,
|
|
@@ -46,7 +46,7 @@ const pluginNodeAddons = () => ({
|
|
|
46
46
|
const getFilename = (resource, pkgName2) => {
|
|
47
47
|
const reg = new RegExp(`node_modules/${pkgName2}/(.+)`);
|
|
48
48
|
const match = resource.match(reg);
|
|
49
|
-
const filename = match
|
|
49
|
+
const filename = match?.[1];
|
|
50
50
|
if (!filename) {
|
|
51
51
|
return "[name].[ext]";
|
|
52
52
|
}
|
|
@@ -35,10 +35,9 @@ const pluginPerformance = () => ({
|
|
|
35
35
|
name: "rsbuild:performance",
|
|
36
36
|
setup(api) {
|
|
37
37
|
api.modifyRsbuildConfig((rsbuildConfig) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(_c = rsbuildConfig.performance) != null ? _c : rsbuildConfig.performance = {};
|
|
38
|
+
if (rsbuildConfig.performance?.profile) {
|
|
39
|
+
if (!rsbuildConfig.performance?.bundleAnalyze) {
|
|
40
|
+
rsbuildConfig.performance ?? (rsbuildConfig.performance = {});
|
|
42
41
|
rsbuildConfig.performance.bundleAnalyze = {
|
|
43
42
|
analyzerMode: "disabled",
|
|
44
43
|
generateStatsFile: true
|
|
@@ -109,13 +109,12 @@ function splitByModule(ctx) {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
function splitBySize(ctx) {
|
|
112
|
-
var _a, _b;
|
|
113
112
|
const { override, userDefinedCacheGroups, defaultConfig, rsbuildConfig } = ctx;
|
|
114
113
|
(0, import_assert.default)(rsbuildConfig.strategy === "split-by-size");
|
|
115
114
|
return {
|
|
116
115
|
...defaultConfig,
|
|
117
|
-
minSize:
|
|
118
|
-
maxSize:
|
|
116
|
+
minSize: rsbuildConfig.minSize ?? 0,
|
|
117
|
+
maxSize: rsbuildConfig.maxSize ?? Infinity,
|
|
119
118
|
...override,
|
|
120
119
|
cacheGroups: {
|
|
121
120
|
...defaultConfig.cacheGroups,
|
|
@@ -176,7 +175,6 @@ function pluginSplitChunks() {
|
|
|
176
175
|
setup(api) {
|
|
177
176
|
api.modifyBundlerChain(
|
|
178
177
|
async (chain, { isServer, isWebWorker, isServiceWorker }) => {
|
|
179
|
-
var _a;
|
|
180
178
|
if (isServer || isWebWorker || isServiceWorker) {
|
|
181
179
|
chain.optimization.splitChunks(false);
|
|
182
180
|
if (isWebWorker || isServiceWorker) {
|
|
@@ -206,7 +204,7 @@ function pluginSplitChunks() {
|
|
|
206
204
|
}
|
|
207
205
|
const override = chunkSplit.strategy === "custom" ? (
|
|
208
206
|
// `chunkSplit.splitChunks` compat for Eden
|
|
209
|
-
|
|
207
|
+
chunkSplit.splitChunks ?? chunkSplit.override
|
|
210
208
|
) : chunkSplit.override;
|
|
211
209
|
const splitChunksOptions = await SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
|
|
212
210
|
defaultConfig,
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -95,12 +95,12 @@ function pluginStartUrl() {
|
|
|
95
95
|
return {
|
|
96
96
|
name: "rsbuild:start-url",
|
|
97
97
|
setup(api) {
|
|
98
|
-
|
|
98
|
+
const onStartServer = async (params) => {
|
|
99
99
|
const { port, routes } = params;
|
|
100
100
|
const config = api.getNormalizedConfig();
|
|
101
101
|
const { startUrl, beforeStartUrl } = config.dev;
|
|
102
|
-
const {
|
|
103
|
-
const shouldOpen = Boolean(startUrl)
|
|
102
|
+
const { https } = api.context.devServer || {};
|
|
103
|
+
const shouldOpen = Boolean(startUrl);
|
|
104
104
|
if (!shouldOpen) {
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
@@ -136,7 +136,9 @@ function pluginStartUrl() {
|
|
|
136
136
|
} else {
|
|
137
137
|
openUrls();
|
|
138
138
|
}
|
|
139
|
-
}
|
|
139
|
+
};
|
|
140
|
+
api.onAfterStartDevServer(onStartServer);
|
|
141
|
+
api.onAfterStartProdServer(onStartServer);
|
|
140
142
|
}
|
|
141
143
|
};
|
|
142
144
|
}
|
|
@@ -28,7 +28,7 @@ var import_shared = require("@rsbuild/shared");
|
|
|
28
28
|
const rspackBuild = async (compiler) => {
|
|
29
29
|
return new Promise((resolve, reject) => {
|
|
30
30
|
compiler.run((err, stats) => {
|
|
31
|
-
if (err ||
|
|
31
|
+
if (err || stats?.hasErrors()) {
|
|
32
32
|
const buildError = err || new Error("Rspack build failed!");
|
|
33
33
|
reject(buildError);
|
|
34
34
|
} else {
|
|
@@ -66,9 +66,9 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
} else {
|
|
69
|
-
const executeResult = await
|
|
69
|
+
const executeResult = await executer?.(compiler);
|
|
70
70
|
await context.hooks.onAfterBuildHook.call({
|
|
71
|
-
stats: executeResult
|
|
71
|
+
stats: executeResult?.stats
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RspackConfig,
|
|
1
|
+
import { type RspackConfig, type RspackCompiler, type RspackMultiCompiler, type CreateDevMiddlewareReturns } from '@rsbuild/shared';
|
|
2
2
|
import { type InitConfigsOptions } from './initConfigs';
|
|
3
3
|
import type { Context } from '../../types';
|
|
4
4
|
export declare function createCompiler({
|
|
@@ -35,6 +35,7 @@ module.exports = __toCommonJS(createCompiler_exports);
|
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
var import_devMiddleware = require("./devMiddleware");
|
|
37
37
|
var import_initConfigs = require("./initConfigs");
|
|
38
|
+
var import_shared2 = require("../shared");
|
|
38
39
|
async function createCompiler({
|
|
39
40
|
context,
|
|
40
41
|
rspackConfigs
|
|
@@ -44,11 +45,26 @@ async function createCompiler({
|
|
|
44
45
|
bundlerConfigs: rspackConfigs
|
|
45
46
|
});
|
|
46
47
|
const { rspack } = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
48
|
+
if (!await (0, import_shared2.isSatisfyRspackVersion)(rspack.rspackVersion)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${import_shared.color.green(
|
|
51
|
+
import_shared2.rspackMinVersion
|
|
52
|
+
)}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
47
55
|
const compiler = rspackConfigs.length === 1 ? rspack(rspackConfigs[0]) : rspack(rspackConfigs);
|
|
48
56
|
let isFirstCompile = true;
|
|
49
57
|
compiler.hooks.watchRun.tap("rsbuild:compiling", () => {
|
|
58
|
+
if (isFirstCompile) {
|
|
59
|
+
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
60
|
+
}
|
|
50
61
|
import_shared.logger.start("Compiling...");
|
|
51
62
|
});
|
|
63
|
+
if ((0, import_shared.isProd)()) {
|
|
64
|
+
compiler.hooks.run.tap("rsbuild:run", () => {
|
|
65
|
+
import_shared.logger.start(`Use Rspack v${rspack.rspackVersion}`);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
52
68
|
compiler.hooks.done.tap("rsbuild:done", async (stats) => {
|
|
53
69
|
const obj = stats.toJson({
|
|
54
70
|
all: false,
|
|
@@ -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.1.
|
|
67
|
+
version: "0.1.3",
|
|
68
68
|
target,
|
|
69
69
|
rootPath,
|
|
70
70
|
distPath,
|
|
@@ -5,6 +5,10 @@ export type InitConfigsOptions = {
|
|
|
5
5
|
pluginStore: PluginStore;
|
|
6
6
|
rsbuildOptions: Required<CreateRsbuildOptions>;
|
|
7
7
|
};
|
|
8
|
+
export declare function initRsbuildConfig({
|
|
9
|
+
context,
|
|
10
|
+
pluginStore
|
|
11
|
+
}: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<void>;
|
|
8
12
|
export declare function initConfigs({
|
|
9
13
|
context,
|
|
10
14
|
pluginStore,
|
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var initConfigs_exports = {};
|
|
20
20
|
__export(initConfigs_exports, {
|
|
21
|
-
initConfigs: () => initConfigs
|
|
21
|
+
initConfigs: () => initConfigs,
|
|
22
|
+
initRsbuildConfig: () => initRsbuildConfig
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(initConfigs_exports);
|
|
24
25
|
var import_shared = require("@rsbuild/shared");
|
|
@@ -35,11 +36,13 @@ async function modifyRsbuildConfig(context) {
|
|
|
35
36
|
context.config = modified;
|
|
36
37
|
(0, import_shared.debug)("modify Rsbuild config done");
|
|
37
38
|
}
|
|
38
|
-
async function
|
|
39
|
+
async function initRsbuildConfig({
|
|
39
40
|
context,
|
|
40
|
-
pluginStore
|
|
41
|
-
rsbuildOptions
|
|
41
|
+
pluginStore
|
|
42
42
|
}) {
|
|
43
|
+
if (context.normalizedConfig) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
43
46
|
await (0, import_shared.initPlugins)({
|
|
44
47
|
pluginAPI: context.pluginAPI,
|
|
45
48
|
pluginStore
|
|
@@ -47,6 +50,13 @@ async function initConfigs({
|
|
|
47
50
|
await modifyRsbuildConfig(context);
|
|
48
51
|
context.normalizedConfig = (0, import_config.normalizeConfig)(context.config);
|
|
49
52
|
(0, import_createContext.updateContextByNormalizedConfig)(context, context.normalizedConfig);
|
|
53
|
+
}
|
|
54
|
+
async function initConfigs({
|
|
55
|
+
context,
|
|
56
|
+
pluginStore,
|
|
57
|
+
rsbuildOptions
|
|
58
|
+
}) {
|
|
59
|
+
await initRsbuildConfig({ context, pluginStore });
|
|
50
60
|
const targets = (0, import_shared.castArray)(rsbuildOptions.target);
|
|
51
61
|
const rspackConfigs = await Promise.all(
|
|
52
62
|
targets.map((target) => (0, import_rspackConfig.generateRspackConfig)({ target, context }))
|
|
@@ -74,5 +84,6 @@ async function initConfigs({
|
|
|
74
84
|
}
|
|
75
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
86
|
0 && (module.exports = {
|
|
77
|
-
initConfigs
|
|
87
|
+
initConfigs,
|
|
88
|
+
initRsbuildConfig
|
|
78
89
|
});
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { type OnExitFn, type OnAfterBuildFn, type OnBeforeBuildFn, type OnDevCompileDoneFn, type ModifyRsbuildConfigFn, type OnAfterStartDevServerFn, type OnBeforeStartDevServerFn, type OnAfterCreateCompilerFn, type OnBeforeCreateCompilerFn, type ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
|
|
1
|
+
import { type OnExitFn, type OnAfterBuildFn, type OnBeforeBuildFn, type OnDevCompileDoneFn, type ModifyRsbuildConfigFn, type OnAfterStartDevServerFn, type OnBeforeStartDevServerFn, type OnAfterStartProdServerFn, type OnBeforeStartProdServerFn, type OnAfterCreateCompilerFn, type OnBeforeCreateCompilerFn, type ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildConfig } from '../../types';
|
|
3
|
-
import type { Compiler, MultiCompiler } from '@rspack/core';
|
|
4
3
|
export declare function initHooks(): {
|
|
5
4
|
/** parameters are not bundler-related */
|
|
6
5
|
onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
|
|
7
6
|
onDevCompileDoneHook: import("@rsbuild/shared").AsyncHook<OnDevCompileDoneFn>;
|
|
8
7
|
onAfterStartDevServerHook: import("@rsbuild/shared").AsyncHook<OnAfterStartDevServerFn>;
|
|
9
8
|
onBeforeStartDevServerHook: import("@rsbuild/shared").AsyncHook<OnBeforeStartDevServerFn>;
|
|
9
|
+
onAfterStartProdServerHook: import("@rsbuild/shared").AsyncHook<OnAfterStartProdServerFn>;
|
|
10
|
+
onBeforeStartProdServerHook: import("@rsbuild/shared").AsyncHook<OnBeforeStartProdServerFn>;
|
|
10
11
|
/** parameters are bundler-related */
|
|
11
12
|
onAfterBuildHook: import("@rsbuild/shared").AsyncHook<OnAfterBuildFn>;
|
|
12
13
|
onBeforeBuildHook: import("@rsbuild/shared").AsyncHook<OnBeforeBuildFn<RspackConfig>>;
|
|
13
14
|
modifyRspackConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRspackConfigFn>;
|
|
14
15
|
modifyRsbuildConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRsbuildConfigFn<RsbuildConfig>>;
|
|
15
|
-
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn
|
|
16
|
+
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn>;
|
|
16
17
|
onBeforeCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnBeforeCreateCompilerFn<RspackConfig>>;
|
|
17
18
|
modifyBundlerChainHook: import("@rsbuild/shared").AsyncHook<ModifyBundlerChainFn>;
|
|
18
19
|
};
|
|
@@ -29,6 +29,8 @@ function initHooks() {
|
|
|
29
29
|
onDevCompileDoneHook: (0, import_shared.createAsyncHook)(),
|
|
30
30
|
onAfterStartDevServerHook: (0, import_shared.createAsyncHook)(),
|
|
31
31
|
onBeforeStartDevServerHook: (0, import_shared.createAsyncHook)(),
|
|
32
|
+
onAfterStartProdServerHook: (0, import_shared.createAsyncHook)(),
|
|
33
|
+
onBeforeStartProdServerHook: (0, import_shared.createAsyncHook)(),
|
|
32
34
|
/** parameters are bundler-related */
|
|
33
35
|
onAfterBuildHook: (0, import_shared.createAsyncHook)(),
|
|
34
36
|
onBeforeBuildHook: (0, import_shared.createAsyncHook)(),
|
|
@@ -75,6 +75,8 @@ function getPluginAPI({
|
|
|
75
75
|
onBeforeCreateCompiler: hooks.onBeforeCreateCompilerHook.tap,
|
|
76
76
|
onAfterStartDevServer: hooks.onAfterStartDevServerHook.tap,
|
|
77
77
|
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap,
|
|
78
|
+
onAfterStartProdServer: hooks.onAfterStartProdServerHook.tap,
|
|
79
|
+
onBeforeStartProdServer: hooks.onBeforeStartProdServerHook.tap,
|
|
78
80
|
modifyWebpackChain: () => {
|
|
79
81
|
},
|
|
80
82
|
modifyWebpackConfig: () => {
|
|
@@ -13,7 +13,18 @@ export declare function inspectConfig({
|
|
|
13
13
|
rsbuildConfig: string;
|
|
14
14
|
bundlerConfigs: string[];
|
|
15
15
|
origin: {
|
|
16
|
-
rsbuildConfig:
|
|
16
|
+
rsbuildConfig: {
|
|
17
|
+
pluginNames: string[];
|
|
18
|
+
dev?: import("@rsbuild/shared").DevConfig | undefined;
|
|
19
|
+
server?: import("@rsbuild/shared").ServerConfig | undefined;
|
|
20
|
+
html?: import("@rsbuild/shared").HtmlConfig | undefined;
|
|
21
|
+
tools?: import("@rsbuild/shared").ToolsConfig | undefined;
|
|
22
|
+
source?: import("@rsbuild/shared").SourceConfig | undefined;
|
|
23
|
+
output?: import("@rsbuild/shared").OutputConfig | undefined;
|
|
24
|
+
security?: import("@rsbuild/shared").SecurityConfig | undefined;
|
|
25
|
+
performance?: import("@rsbuild/shared").PerformanceConfig | undefined;
|
|
26
|
+
plugins?: import("@rsbuild/shared").RsbuildPlugin[] | undefined;
|
|
27
|
+
};
|
|
17
28
|
bundlerConfigs: RspackConfig[];
|
|
18
29
|
};
|
|
19
30
|
}>;
|
|
@@ -36,13 +36,17 @@ async function inspectConfig({
|
|
|
36
36
|
} else if (!process.env.NODE_ENV) {
|
|
37
37
|
process.env.NODE_ENV = "development";
|
|
38
38
|
}
|
|
39
|
+
const rsbuildDebugConfig = {
|
|
40
|
+
...context.config,
|
|
41
|
+
pluginNames: pluginStore.plugins.map((p) => p.name)
|
|
42
|
+
};
|
|
39
43
|
const rspackConfigs = bundlerConfigs || (await (0, import_initConfigs.initConfigs)({
|
|
40
44
|
context,
|
|
41
45
|
pluginStore,
|
|
42
46
|
rsbuildOptions
|
|
43
47
|
})).rspackConfigs;
|
|
44
48
|
const rawRsbuildConfig = await (0, import_shared.stringifyConfig)(
|
|
45
|
-
|
|
49
|
+
rsbuildDebugConfig,
|
|
46
50
|
inspectOptions.verbose
|
|
47
51
|
);
|
|
48
52
|
const rawBundlerConfigs = await Promise.all(
|
|
@@ -70,7 +74,7 @@ async function inspectConfig({
|
|
|
70
74
|
rsbuildConfig: rawRsbuildConfig,
|
|
71
75
|
bundlerConfigs: rawBundlerConfigs,
|
|
72
76
|
origin: {
|
|
73
|
-
rsbuildConfig:
|
|
77
|
+
rsbuildConfig: rsbuildDebugConfig,
|
|
74
78
|
bundlerConfigs: rspackConfigs
|
|
75
79
|
}
|
|
76
80
|
};
|
|
@@ -34,13 +34,12 @@ module.exports = __toCommonJS(rspackConfig_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
var import_shared2 = require("../shared");
|
|
36
36
|
async function modifyRspackConfig(context, rspackConfig, utils) {
|
|
37
|
-
var _a;
|
|
38
37
|
(0, import_shared.debug)("modify Rspack config");
|
|
39
38
|
let [modifiedConfig] = await context.hooks.modifyRspackConfigHook.call(
|
|
40
39
|
rspackConfig,
|
|
41
40
|
utils
|
|
42
41
|
);
|
|
43
|
-
if (
|
|
42
|
+
if (context.config.tools?.rspack) {
|
|
44
43
|
modifiedConfig = (0, import_shared.mergeChainedOptions)({
|
|
45
44
|
defaults: modifiedConfig,
|
|
46
45
|
options: context.config.tools.rspack,
|
|
@@ -109,13 +108,19 @@ async function generateRspackConfig({
|
|
|
109
108
|
context
|
|
110
109
|
}) {
|
|
111
110
|
const chainUtils = await getChainUtils(target);
|
|
112
|
-
const {
|
|
111
|
+
const {
|
|
112
|
+
BannerPlugin,
|
|
113
|
+
DefinePlugin,
|
|
114
|
+
ProvidePlugin,
|
|
115
|
+
HotModuleReplacementPlugin
|
|
116
|
+
} = await Promise.resolve().then(() => __toESM(require("@rspack/core")));
|
|
113
117
|
const chain = await (0, import_shared.modifyBundlerChain)(context, {
|
|
114
118
|
...chainUtils,
|
|
115
119
|
bundler: {
|
|
116
120
|
BannerPlugin,
|
|
117
121
|
DefinePlugin,
|
|
118
|
-
ProvidePlugin
|
|
122
|
+
ProvidePlugin,
|
|
123
|
+
HotModuleReplacementPlugin
|
|
119
124
|
}
|
|
120
125
|
});
|
|
121
126
|
let rspackConfig = chain.toConfig();
|
|
@@ -2,4 +2,5 @@ export { getRspackVersion } from './shared';
|
|
|
2
2
|
export { rspackProvider } from './provider';
|
|
3
3
|
export type { RspackProvider } from './provider';
|
|
4
4
|
export type { Rspack, RspackConfig } from '@rsbuild/shared';
|
|
5
|
-
export { createPublicContext, createContextByConfig
|
|
5
|
+
export { createPublicContext, createContextByConfig } from './core/createContext';
|
|
6
|
+
export { initRsbuildConfig } from './core/initConfigs';
|