@rsbuild/core 0.0.19 → 0.0.21
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/cli/commands.js +2 -2
- package/dist/cli/config.js +19 -2
- package/dist/cli/index.d.ts +1 -5
- package/dist/cli/index.js +3 -21
- package/dist/cli/run.d.ts +7 -0
- package/dist/{server/constants.js → cli/run.js} +27 -27
- package/dist/plugins/asset.d.ts +1 -1
- package/dist/plugins/asset.js +19 -13
- package/dist/plugins/cache.js +8 -8
- package/dist/plugins/cleanOutput.js +3 -3
- package/dist/plugins/fileSize.js +24 -24
- package/dist/plugins/html.js +6 -24
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -5
- package/dist/plugins/inlineChunk.js +2 -7
- package/dist/plugins/rem.js +2 -2
- package/dist/plugins/splitChunks.js +0 -5
- package/dist/plugins/startUrl.js +4 -2
- package/dist/rspack-provider/core/initHooks.d.ts +4 -3
- package/dist/rspack-provider/core/initPlugins.js +5 -1
- package/dist/rspack-provider/index.d.ts +1 -1
- package/dist/rspack-provider/plugins/rspack-profile.js +6 -6
- package/dist/rspack-provider/plugins/swc.js +1 -2
- package/dist/rspack-provider/provider.js +2 -2
- package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.d.ts +1 -1
- package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.js +4 -4
- package/dist/rspack-provider/shared/fs.js +2 -2
- package/dist/rspack-provider/shared/plugin.js +1 -4
- package/dist/rspack-provider/types/index.d.ts +0 -1
- package/dist/rspack-provider/types/index.js +0 -2
- package/dist/rspack-provider/types/plugin.d.ts +1 -4
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.d.ts +1 -1
- package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +1 -1
- package/dist/server/dev-middleware/hmr-client/index.js +2 -25
- package/dist/server/dev-middleware/index.d.ts +2 -2
- package/dist/server/dev-middleware/index.js +1 -1
- package/dist/server/dev-middleware/socketServer.d.ts +2 -2
- package/dist/server/dev-middleware/socketServer.js +1 -4
- package/dist/server/devServer.d.ts +1 -2
- package/dist/server/devServer.js +28 -14
- package/dist/server/middlewares.d.ts +7 -1
- package/dist/server/middlewares.js +70 -2
- package/dist/server/prodServer.d.ts +4 -2
- package/dist/server/prodServer.js +12 -2
- package/dist/server/restart.d.ts +11 -0
- package/dist/server/restart.js +64 -0
- package/package.json +3 -29
- package/types.d.ts +63 -23
- package/dist/rspack-provider/types/hooks.d.ts +0 -3
- package/dist/rspack-provider/types/hooks.js +0 -16
- package/dist/server/constants.d.ts +0 -6
package/dist/cli/commands.js
CHANGED
|
@@ -22,11 +22,11 @@ __export(commands_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(commands_exports);
|
|
24
24
|
var import_path = require("path");
|
|
25
|
-
var
|
|
25
|
+
var import_shared = require("@rsbuild/shared");
|
|
26
26
|
var import_commander = require("commander");
|
|
27
27
|
function setupProgram(rsbuild) {
|
|
28
28
|
const pkgJson = (0, import_path.join)(__dirname, "../../package.json");
|
|
29
|
-
const { version } =
|
|
29
|
+
const { version } = import_shared.fse.readJSONSync(pkgJson);
|
|
30
30
|
import_commander.program.name("rsbuild").usage("<command> [options]").version(version);
|
|
31
31
|
import_commander.program.command("dev").option(`--open`, "open the page in browser on startup").description("starting the dev server").action(async (options) => {
|
|
32
32
|
await rsbuild.startDevServer({
|
package/dist/cli/config.js
CHANGED
|
@@ -33,10 +33,11 @@ __export(config_exports, {
|
|
|
33
33
|
loadConfig: () => loadConfig
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(config_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
36
37
|
var import_jiti = __toESM(require("jiti"));
|
|
37
38
|
var import_path = require("path");
|
|
38
39
|
var import_shared = require("@rsbuild/shared");
|
|
39
|
-
var
|
|
40
|
+
var import_restart = require("../server/restart");
|
|
40
41
|
const defineConfig = (config) => config;
|
|
41
42
|
const resolveConfigPath = () => {
|
|
42
43
|
const CONFIG_FILES = [
|
|
@@ -50,19 +51,35 @@ const resolveConfigPath = () => {
|
|
|
50
51
|
const root = process.cwd();
|
|
51
52
|
for (const file of CONFIG_FILES) {
|
|
52
53
|
const configFile = (0, import_path.join)(root, file);
|
|
53
|
-
if (
|
|
54
|
+
if (import_fs.default.existsSync(configFile)) {
|
|
54
55
|
return configFile;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
return null;
|
|
58
59
|
};
|
|
60
|
+
async function watchConfig(configFile) {
|
|
61
|
+
const chokidar = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/chokidar")));
|
|
62
|
+
const watcher = chokidar.watch(configFile, {});
|
|
63
|
+
const callback = async () => {
|
|
64
|
+
watcher.close();
|
|
65
|
+
await (0, import_restart.restartDevServer)({ filePath: configFile });
|
|
66
|
+
};
|
|
67
|
+
watcher.on("change", callback);
|
|
68
|
+
watcher.on("unlink", callback);
|
|
69
|
+
}
|
|
59
70
|
async function loadConfig() {
|
|
60
71
|
const configFile = resolveConfigPath();
|
|
61
72
|
if (configFile) {
|
|
62
73
|
const loadConfig2 = (0, import_jiti.default)(__filename, {
|
|
63
74
|
esmResolve: true,
|
|
75
|
+
// disable require cache to support restart CLI and read the new config
|
|
76
|
+
requireCache: false,
|
|
64
77
|
interopDefault: true
|
|
65
78
|
});
|
|
79
|
+
const command = process.argv[2];
|
|
80
|
+
if (command === "dev") {
|
|
81
|
+
watchConfig(configFile);
|
|
82
|
+
}
|
|
66
83
|
return loadConfig2(configFile);
|
|
67
84
|
}
|
|
68
85
|
return {};
|
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -18,30 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var cli_exports = {};
|
|
20
20
|
__export(cli_exports, {
|
|
21
|
-
defineConfig: () =>
|
|
22
|
-
runCli: () => runCli
|
|
21
|
+
defineConfig: () => import_config.defineConfig,
|
|
22
|
+
runCli: () => import_run.runCli
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(cli_exports);
|
|
25
|
-
var import__ = require("..");
|
|
26
|
-
var import_commands = require("./commands");
|
|
27
25
|
var import_config = require("./config");
|
|
28
|
-
var
|
|
29
|
-
async function runCli(options = {}) {
|
|
30
|
-
var _a;
|
|
31
|
-
const config = await (0, import_config.loadConfig)();
|
|
32
|
-
const rsbuild = await (0, import__.createRsbuild)({
|
|
33
|
-
rsbuildConfig: config,
|
|
34
|
-
entry: ((_a = config.source) == null ? void 0 : _a.entries) || (0, import_config.getDefaultEntries)(),
|
|
35
|
-
provider: config.provider
|
|
36
|
-
});
|
|
37
|
-
if (options.defaultPlugins) {
|
|
38
|
-
rsbuild.addPlugins(options.defaultPlugins);
|
|
39
|
-
}
|
|
40
|
-
if (config.plugins) {
|
|
41
|
-
rsbuild.addPlugins(config.plugins);
|
|
42
|
-
}
|
|
43
|
-
(0, import_commands.setupProgram)(rsbuild);
|
|
44
|
-
}
|
|
26
|
+
var import_run = require("./run");
|
|
45
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
28
|
0 && (module.exports = {
|
|
47
29
|
defineConfig,
|
|
@@ -16,34 +16,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
22
|
-
getDefaultDevOptions: () => getDefaultDevOptions
|
|
19
|
+
var run_exports = {};
|
|
20
|
+
__export(run_exports, {
|
|
21
|
+
runCli: () => runCli
|
|
23
22
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
23
|
+
module.exports = __toCommonJS(run_exports);
|
|
24
|
+
var import__ = require("..");
|
|
25
|
+
var import_commands = require("./commands");
|
|
26
|
+
var import_config = require("./config");
|
|
27
|
+
async function runCli(options = {}) {
|
|
28
|
+
var _a;
|
|
29
|
+
const config = await (0, import_config.loadConfig)();
|
|
30
|
+
const rsbuild = await (0, import__.createRsbuild)({
|
|
31
|
+
rsbuildConfig: config,
|
|
32
|
+
entry: ((_a = config.source) == null ? void 0 : _a.entries) || (0, import_config.getDefaultEntries)(),
|
|
33
|
+
provider: config.provider
|
|
34
|
+
});
|
|
35
|
+
if (options.defaultPlugins) {
|
|
36
|
+
rsbuild.addPlugins(options.defaultPlugins);
|
|
37
|
+
}
|
|
38
|
+
if (config.plugins) {
|
|
39
|
+
rsbuild.addPlugins(config.plugins);
|
|
40
|
+
}
|
|
41
|
+
if (!options.isRestart) {
|
|
42
|
+
(0, import_commands.setupProgram)(rsbuild);
|
|
43
|
+
}
|
|
44
|
+
return rsbuild;
|
|
45
|
+
}
|
|
45
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
47
|
0 && (module.exports = {
|
|
47
|
-
|
|
48
|
-
getDefaultDevOptions
|
|
48
|
+
runCli
|
|
49
49
|
});
|
package/dist/plugins/asset.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DefaultRsbuildPlugin } from '@rsbuild/shared';
|
|
2
2
|
export declare function getRegExpForExts(exts: string[]): RegExp;
|
|
3
|
-
export declare const pluginAsset: (
|
|
3
|
+
export declare const pluginAsset: () => DefaultRsbuildPlugin;
|
package/dist/plugins/asset.js
CHANGED
|
@@ -41,22 +41,28 @@ function getRegExpForExts(exts) {
|
|
|
41
41
|
"i"
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
const pluginAsset = (
|
|
45
|
-
name:
|
|
44
|
+
const pluginAsset = () => ({
|
|
45
|
+
name: "plugin-asset",
|
|
46
46
|
setup(api) {
|
|
47
47
|
api.modifyBundlerChain((chain, { isProd }) => {
|
|
48
48
|
const config = api.getNormalizedConfig();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
const createAssetRule = (assetType, exts) => {
|
|
50
|
+
const regExp = getRegExpForExts(exts);
|
|
51
|
+
const distDir = (0, import_shared.getDistPath)(config.output, assetType);
|
|
52
|
+
const filename = (0, import_shared.getFilename)(config.output, assetType, isProd);
|
|
53
|
+
const maxSize = config.output.dataUriLimit[assetType];
|
|
54
|
+
const rule = chain.module.rule(assetType).test(regExp);
|
|
55
|
+
(0, import_shared.chainStaticAssetRule)({
|
|
56
|
+
rule,
|
|
57
|
+
maxSize,
|
|
58
|
+
filename: import_path.default.posix.join(distDir, filename),
|
|
59
|
+
assetType
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
createAssetRule("image", import_shared.IMAGE_EXTENSIONS);
|
|
63
|
+
createAssetRule("svg", ["svg"]);
|
|
64
|
+
createAssetRule("media", import_shared.MEDIA_EXTENSIONS);
|
|
65
|
+
createAssetRule("font", import_shared.FONT_EXTENSIONS);
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
});
|
package/dist/plugins/cache.js
CHANGED
|
@@ -33,18 +33,18 @@ __export(cache_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(cache_exports);
|
|
34
34
|
var import_crypto = __toESM(require("crypto"));
|
|
35
35
|
var import_path = require("path");
|
|
36
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
37
36
|
var import_shared = require("@rsbuild/shared");
|
|
37
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
38
38
|
async function validateCache(cacheDirectory, buildDependencies) {
|
|
39
39
|
const configFile = (0, import_path.join)(cacheDirectory, "buildDependencies.json");
|
|
40
|
-
if (await (0,
|
|
41
|
-
const prevBuildDependencies = await
|
|
40
|
+
if (await (0, import_shared2.isFileExists)(configFile)) {
|
|
41
|
+
const prevBuildDependencies = await import_shared.fse.readJSON(configFile);
|
|
42
42
|
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
await
|
|
45
|
+
await import_shared.fse.remove(cacheDirectory);
|
|
46
46
|
}
|
|
47
|
-
await
|
|
47
|
+
await import_shared.fse.outputJSON(configFile, buildDependencies);
|
|
48
48
|
}
|
|
49
49
|
function getDigestHash(digest) {
|
|
50
50
|
const fsHash = import_crypto.default.createHash("md5");
|
|
@@ -61,7 +61,7 @@ async function getBuildDependencies(context) {
|
|
|
61
61
|
const rootPackageJson = (0, import_path.join)(context.rootPath, "package.json");
|
|
62
62
|
const browserslistConfig = (0, import_path.join)(context.rootPath, ".browserslistrc");
|
|
63
63
|
const buildDependencies = {};
|
|
64
|
-
if (await (0,
|
|
64
|
+
if (await (0, import_shared2.isFileExists)(rootPackageJson)) {
|
|
65
65
|
buildDependencies.packageJson = [rootPackageJson];
|
|
66
66
|
}
|
|
67
67
|
if (context.configPath) {
|
|
@@ -70,14 +70,14 @@ async function getBuildDependencies(context) {
|
|
|
70
70
|
if (context.tsconfigPath) {
|
|
71
71
|
buildDependencies.tsconfig = [context.tsconfigPath];
|
|
72
72
|
}
|
|
73
|
-
if (await (0,
|
|
73
|
+
if (await (0, import_shared2.isFileExists)(browserslistConfig)) {
|
|
74
74
|
buildDependencies.browserslistrc = [browserslistConfig];
|
|
75
75
|
}
|
|
76
76
|
const tailwindExts = ["ts", "js", "cjs", "mjs"];
|
|
77
77
|
const configs = tailwindExts.map(
|
|
78
78
|
(ext) => (0, import_path.join)(context.rootPath, `tailwind.config.${ext}`)
|
|
79
79
|
);
|
|
80
|
-
const tailwindConfig = (0,
|
|
80
|
+
const tailwindConfig = (0, import_shared2.findExists)(configs);
|
|
81
81
|
if (tailwindConfig) {
|
|
82
82
|
buildDependencies.tailwindcss = [tailwindConfig];
|
|
83
83
|
}
|
|
@@ -21,10 +21,10 @@ __export(cleanOutput_exports, {
|
|
|
21
21
|
pluginCleanOutput: () => pluginCleanOutput
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(cleanOutput_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_shared = require("@rsbuild/shared");
|
|
25
25
|
const emptyDir = async (dir) => {
|
|
26
|
-
if (await
|
|
27
|
-
await
|
|
26
|
+
if (await import_shared.fse.pathExists(dir)) {
|
|
27
|
+
await import_shared.fse.emptyDir(dir);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
const pluginCleanOutput = () => ({
|
package/dist/plugins/fileSize.js
CHANGED
|
@@ -33,19 +33,18 @@ __export(fileSize_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(fileSize_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
37
36
|
var import_shared = require("@rsbuild/shared");
|
|
38
|
-
var
|
|
37
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
39
38
|
var import_gzip_size = __toESM(require("gzip-size"));
|
|
40
39
|
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
41
40
|
const getAssetColor = (size) => {
|
|
42
41
|
if (size > 300 * 1e3) {
|
|
43
|
-
return
|
|
42
|
+
return import_shared2.color.red;
|
|
44
43
|
}
|
|
45
44
|
if (size > 100 * 1e3) {
|
|
46
|
-
return
|
|
45
|
+
return import_shared2.color.yellow;
|
|
47
46
|
}
|
|
48
|
-
return
|
|
47
|
+
return import_shared2.color.green;
|
|
49
48
|
};
|
|
50
49
|
async function printHeader(longestFileLength, longestLabelLength) {
|
|
51
50
|
const longestLengths = [longestFileLength, longestLabelLength];
|
|
@@ -57,11 +56,15 @@ async function printHeader(longestFileLength, longestLabelLength) {
|
|
|
57
56
|
}
|
|
58
57
|
return `${prev + curLabel} `;
|
|
59
58
|
}, " ");
|
|
60
|
-
|
|
59
|
+
import_shared2.logger.log(import_shared2.color.bold(import_shared2.color.blue(headerRow)));
|
|
61
60
|
}
|
|
61
|
+
const calcFileSize = (len) => {
|
|
62
|
+
const val = len / 1e3;
|
|
63
|
+
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
64
|
+
};
|
|
62
65
|
async function printFileSizes(stats, distPath) {
|
|
63
66
|
const formatAsset = (asset) => {
|
|
64
|
-
const contents =
|
|
67
|
+
const contents = import_shared.fse.readFileSync(import_path.default.join(distPath, asset.name));
|
|
65
68
|
const size = contents.length;
|
|
66
69
|
const gzippedSize = import_gzip_size.default.sync(contents);
|
|
67
70
|
return {
|
|
@@ -69,10 +72,8 @@ async function printFileSizes(stats, distPath) {
|
|
|
69
72
|
folder: import_path.default.join(import_path.default.basename(distPath), import_path.default.dirname(asset.name)),
|
|
70
73
|
name: import_path.default.basename(asset.name),
|
|
71
74
|
gzippedSize,
|
|
72
|
-
sizeLabel: (
|
|
73
|
-
gzipSizeLabel: getAssetColor(gzippedSize)(
|
|
74
|
-
(0, import_filesize.default)(gzippedSize, { round: 1 })
|
|
75
|
-
)
|
|
75
|
+
sizeLabel: calcFileSize(size),
|
|
76
|
+
gzipSizeLabel: getAssetColor(gzippedSize)(calcFileSize(gzippedSize))
|
|
76
77
|
};
|
|
77
78
|
};
|
|
78
79
|
const multiStats = "stats" in stats ? stats.stats : [stats];
|
|
@@ -100,7 +101,7 @@ async function printFileSizes(stats, distPath) {
|
|
|
100
101
|
const longestFileLength = Math.max(
|
|
101
102
|
...assets.map((a) => (a.folder + import_path.default.sep + a.name).length)
|
|
102
103
|
);
|
|
103
|
-
|
|
104
|
+
import_shared2.logger.info(`Production file sizes:
|
|
104
105
|
`);
|
|
105
106
|
printHeader(longestFileLength, longestLabelLength);
|
|
106
107
|
let totalSize = 0;
|
|
@@ -116,21 +117,20 @@ async function printFileSizes(stats, distPath) {
|
|
|
116
117
|
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
117
118
|
sizeLabel += rightPadding;
|
|
118
119
|
}
|
|
119
|
-
let fileNameLabel =
|
|
120
|
+
let fileNameLabel = import_shared2.color.dim(asset.folder + import_path.default.sep) + import_shared2.color.cyan(asset.name);
|
|
120
121
|
if (fileNameLength < longestFileLength) {
|
|
121
122
|
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
122
123
|
fileNameLabel += rightPadding;
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
+
import_shared2.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
125
126
|
});
|
|
126
|
-
const totalSizeLabel = `${
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
import_shared.logger.log(`
|
|
127
|
+
const totalSizeLabel = `${import_shared2.color.bold(
|
|
128
|
+
import_shared2.color.blue("Total size:")
|
|
129
|
+
)} ${calcFileSize(totalSize)}`;
|
|
130
|
+
const gzippedSizeLabel = `${import_shared2.color.bold(
|
|
131
|
+
import_shared2.color.blue("Gzipped size:")
|
|
132
|
+
)} ${calcFileSize(totalGzipSize)}`;
|
|
133
|
+
import_shared2.logger.log(`
|
|
134
134
|
${totalSizeLabel}
|
|
135
135
|
${gzippedSizeLabel}
|
|
136
136
|
`);
|
|
@@ -144,8 +144,8 @@ const pluginFileSize = () => ({
|
|
|
144
144
|
try {
|
|
145
145
|
await printFileSizes(stats, api.context.distPath);
|
|
146
146
|
} catch (err) {
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
import_shared2.logger.error("Failed to print file size.");
|
|
148
|
+
import_shared2.logger.error(err);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
});
|
package/dist/plugins/html.js
CHANGED
|
@@ -40,8 +40,6 @@ __export(html_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(html_exports);
|
|
41
41
|
var import_path = __toESM(require("path"));
|
|
42
42
|
var import_shared = require("@rsbuild/shared");
|
|
43
|
-
var import_fs_extra = require("@rsbuild/shared/fs-extra");
|
|
44
|
-
var import_lodash = __toESM(require("lodash"));
|
|
45
43
|
var import_HtmlBasicPlugin = require("../rspack-plugins/HtmlBasicPlugin");
|
|
46
44
|
function getTitle(entryName, config) {
|
|
47
45
|
return (0, import_shared.mergeChainedOptions)({
|
|
@@ -133,11 +131,13 @@ const applyInjectTags = (api) => {
|
|
|
133
131
|
api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID }) => {
|
|
134
132
|
const config = api.getNormalizedConfig();
|
|
135
133
|
const tags = (0, import_shared.castArray)(config.html.tags).filter(Boolean);
|
|
136
|
-
const tagsByEntries =
|
|
137
|
-
|
|
138
|
-
(
|
|
134
|
+
const tagsByEntries = config.html.tagsByEntries || {};
|
|
135
|
+
Object.keys(tagsByEntries).forEach(
|
|
136
|
+
(key) => tagsByEntries[key] = (0, import_shared.castArray)(tagsByEntries[key]).filter(Boolean)
|
|
137
|
+
);
|
|
138
|
+
const shouldByEntries = Object.values(tagsByEntries).some(
|
|
139
|
+
(entry) => Array.isArray(entry) && entry.length > 0
|
|
139
140
|
);
|
|
140
|
-
const shouldByEntries = import_lodash.default.some(tagsByEntries, "length");
|
|
141
141
|
if (!tags.length && !shouldByEntries) {
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
@@ -163,7 +163,6 @@ const applyInjectTags = (api) => {
|
|
|
163
163
|
const pluginHtml = () => ({
|
|
164
164
|
name: "plugin-html",
|
|
165
165
|
setup(api) {
|
|
166
|
-
const routesInfo = [];
|
|
167
166
|
api.modifyBundlerChain(
|
|
168
167
|
async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
|
|
169
168
|
const config = api.getNormalizedConfig();
|
|
@@ -225,12 +224,6 @@ const pluginHtml = () => ({
|
|
|
225
224
|
entryValue
|
|
226
225
|
}
|
|
227
226
|
});
|
|
228
|
-
routesInfo.push({
|
|
229
|
-
urlPath: index === 0 ? "/" : `/${entryName}`,
|
|
230
|
-
entryName,
|
|
231
|
-
entryPath: filename,
|
|
232
|
-
isSPA: true
|
|
233
|
-
});
|
|
234
227
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).use(HtmlPlugin, [finalOptions]);
|
|
235
228
|
})
|
|
236
229
|
);
|
|
@@ -261,17 +254,6 @@ const pluginHtml = () => ({
|
|
|
261
254
|
}
|
|
262
255
|
}
|
|
263
256
|
);
|
|
264
|
-
const emitRouteJson = async () => {
|
|
265
|
-
const routeFilePath = import_path.default.join(api.context.distPath, import_shared.ROUTE_SPEC_FILE);
|
|
266
|
-
if (!await (0, import_shared.isFileExists)(routeFilePath) && routesInfo.length) {
|
|
267
|
-
await import_fs_extra.fs.outputFile(
|
|
268
|
-
routeFilePath,
|
|
269
|
-
JSON.stringify({ routes: routesInfo }, null, 2)
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
api.onBeforeBuild(emitRouteJson);
|
|
274
|
-
api.onBeforeStartDevServer(emitRouteJson);
|
|
275
257
|
applyInjectTags(api);
|
|
276
258
|
}
|
|
277
259
|
});
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugins } from '@rsbuild/shared';
|
|
1
|
+
import type { Plugins } from '@rsbuild/shared';
|
|
2
2
|
export declare const plugins: Plugins;
|
package/dist/plugins/index.js
CHANGED
|
@@ -31,7 +31,6 @@ __export(plugins_exports, {
|
|
|
31
31
|
plugins: () => plugins
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(plugins_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
const plugins = {
|
|
36
35
|
html: () => Promise.resolve().then(() => __toESM(require("./html"))).then((m) => m.pluginHtml()),
|
|
37
36
|
cleanOutput: () => Promise.resolve().then(() => __toESM(require("./cleanOutput"))).then((m) => m.pluginCleanOutput()),
|
|
@@ -46,10 +45,7 @@ const plugins = {
|
|
|
46
45
|
splitChunks: () => Promise.resolve().then(() => __toESM(require("./splitChunks"))).then((m) => m.pluginSplitChunks()),
|
|
47
46
|
inlineChunk: () => Promise.resolve().then(() => __toESM(require("./inlineChunk"))).then((m) => m.pluginInlineChunk()),
|
|
48
47
|
bundleAnalyzer: () => Promise.resolve().then(() => __toESM(require("./bundleAnalyzer"))).then((m) => m.pluginBundleAnalyzer()),
|
|
49
|
-
|
|
50
|
-
font: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("font", import_shared.FONT_EXTENSIONS)),
|
|
51
|
-
image: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("image", import_shared.IMAGE_EXTENSIONS)),
|
|
52
|
-
media: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset("media", import_shared.MEDIA_EXTENSIONS)),
|
|
48
|
+
asset: () => Promise.resolve().then(() => __toESM(require("./asset"))).then((m) => m.pluginAsset()),
|
|
53
49
|
rem: () => Promise.resolve().then(() => __toESM(require("./rem"))).then((m) => m.pluginRem()),
|
|
54
50
|
wasm: () => Promise.resolve().then(() => __toESM(require("./wasm"))).then((m) => m.pluginWasm()),
|
|
55
51
|
moment: () => Promise.resolve().then(() => __toESM(require("./moment"))).then((m) => m.pluginMoment()),
|
|
@@ -43,7 +43,6 @@ const pluginInlineChunk = () => ({
|
|
|
43
43
|
}
|
|
44
44
|
const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
|
|
45
45
|
const {
|
|
46
|
-
disableInlineRuntimeChunk,
|
|
47
46
|
enableInlineStyles,
|
|
48
47
|
// todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
|
|
49
48
|
enableInlineScripts
|
|
@@ -60,12 +59,8 @@ const pluginInlineChunk = () => ({
|
|
|
60
59
|
enableInlineStyles === true ? import_shared.CSS_REGEX : enableInlineStyles
|
|
61
60
|
);
|
|
62
61
|
}
|
|
63
|
-
if (!
|
|
64
|
-
|
|
65
|
-
// RegExp like /bundler-runtime([.].+)?\.js$/
|
|
66
|
-
// matches bundler-runtime.js and bundler-runtime.123456.js
|
|
67
|
-
new RegExp(`${import_shared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
|
|
68
|
-
);
|
|
62
|
+
if (!scriptTests.length && !styleTests.length) {
|
|
63
|
+
return;
|
|
69
64
|
}
|
|
70
65
|
chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
|
|
71
66
|
HtmlPlugin,
|
package/dist/plugins/rem.js
CHANGED
|
@@ -31,8 +31,8 @@ __export(rem_exports, {
|
|
|
31
31
|
pluginRem: () => pluginRem
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(rem_exports);
|
|
34
|
-
var import_lodash = __toESM(require("lodash"));
|
|
35
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
var import_shared2 = require("@rsbuild/shared");
|
|
36
36
|
const defaultOptions = {
|
|
37
37
|
enableRuntime: true,
|
|
38
38
|
rootFontSize: 50
|
|
@@ -65,7 +65,7 @@ const pluginRem = () => ({
|
|
|
65
65
|
rootValue: userOptions.rootFontSize,
|
|
66
66
|
unitPrecision: 5,
|
|
67
67
|
propList: ["*"],
|
|
68
|
-
...
|
|
68
|
+
...userOptions.pxtorem ? (0, import_shared2.cloneDeep)(userOptions.pxtorem) : {}
|
|
69
69
|
});
|
|
70
70
|
applyRules.forEach((name) => {
|
|
71
71
|
chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
|
|
@@ -226,11 +226,6 @@ function pluginSplitChunks() {
|
|
|
226
226
|
polyfill: config.output.polyfill
|
|
227
227
|
});
|
|
228
228
|
chain.optimization.splitChunks(splitChunksOptions);
|
|
229
|
-
if (chunkSplit.strategy !== "all-in-one") {
|
|
230
|
-
chain.optimization.runtimeChunk({
|
|
231
|
-
name: import_shared.RUNTIME_CHUNK_NAME
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
229
|
}
|
|
235
230
|
);
|
|
236
231
|
}
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -96,7 +96,7 @@ function pluginStartUrl() {
|
|
|
96
96
|
name: "plugin-start-url",
|
|
97
97
|
setup(api) {
|
|
98
98
|
api.onAfterStartDevServer(async (params) => {
|
|
99
|
-
const { port } = params;
|
|
99
|
+
const { port, routes } = params;
|
|
100
100
|
const config = api.getNormalizedConfig();
|
|
101
101
|
const { startUrl, beforeStartUrl } = config.dev;
|
|
102
102
|
const { open, https } = api.context.devServer || {};
|
|
@@ -107,7 +107,9 @@ function pluginStartUrl() {
|
|
|
107
107
|
const urls = [];
|
|
108
108
|
if (startUrl === true || !startUrl) {
|
|
109
109
|
const protocol = https ? "https" : "http";
|
|
110
|
-
urls.push(
|
|
110
|
+
urls.push(
|
|
111
|
+
(0, import_shared.normalizeUrl)(`${protocol}://localhost:${port}/${routes[0].route}`)
|
|
112
|
+
);
|
|
111
113
|
} else {
|
|
112
114
|
urls.push(
|
|
113
115
|
...(0, import_shared.castArray)(startUrl).map(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig } from '@rsbuild/shared';
|
|
2
|
-
import type { RsbuildConfig
|
|
1
|
+
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn, ModifyBundlerChainFn, type RspackConfig, type ModifyRspackConfigFn } from '@rsbuild/shared';
|
|
2
|
+
import type { RsbuildConfig } from '../types';
|
|
3
|
+
import type { Compiler, MultiCompiler } from '@rspack/core';
|
|
3
4
|
export declare function initHooks(): {
|
|
4
5
|
/** parameters are not bundler-related */
|
|
5
6
|
onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
|
|
@@ -11,7 +12,7 @@ export declare function initHooks(): {
|
|
|
11
12
|
onBeforeBuildHook: import("@rsbuild/shared").AsyncHook<OnBeforeBuildFn<RspackConfig>>;
|
|
12
13
|
modifyRspackConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRspackConfigFn>;
|
|
13
14
|
modifyRsbuildConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRsbuildConfigFn<RsbuildConfig>>;
|
|
14
|
-
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn<
|
|
15
|
+
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn<Compiler | MultiCompiler>>;
|
|
15
16
|
onBeforeCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnBeforeCreateCompilerFn<RspackConfig>>;
|
|
16
17
|
modifyBundlerChainHook: import("@rsbuild/shared").AsyncHook<ModifyBundlerChainFn>;
|
|
17
18
|
};
|
|
@@ -73,7 +73,11 @@ function getPluginAPI({
|
|
|
73
73
|
onAfterCreateCompiler: hooks.onAfterCreateCompilerHook.tap,
|
|
74
74
|
onBeforeCreateCompiler: hooks.onBeforeCreateCompilerHook.tap,
|
|
75
75
|
onAfterStartDevServer: hooks.onAfterStartDevServerHook.tap,
|
|
76
|
-
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap
|
|
76
|
+
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap,
|
|
77
|
+
modifyWebpackChain: () => {
|
|
78
|
+
},
|
|
79
|
+
modifyWebpackConfig: () => {
|
|
80
|
+
}
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getRspackVersion } from './shared/rspackVersion';
|
|
2
2
|
export { rspackProvider } from './provider';
|
|
3
3
|
export type { RspackProvider } from './provider';
|
|
4
|
-
export type { RsbuildConfig, NormalizedConfig,
|
|
4
|
+
export type { RsbuildConfig, NormalizedConfig, RsbuildPluginAPI } from './types';
|
|
5
5
|
export type { Rspack, RspackConfig } from '@rsbuild/shared';
|