@winner-fed/bundler-rsbuild 0.19.4-alpha.0 → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +40 -0
  2. package/dist/build.d.ts +13 -14
  3. package/dist/build.js +72 -120
  4. package/dist/cli.d.ts +1 -1
  5. package/dist/cli.js +57 -87
  6. package/dist/config/config.d.ts +27 -17
  7. package/dist/config/config.js +96 -145
  8. package/dist/config/devConfig.d.ts +3 -11
  9. package/dist/config/devConfig.js +8 -34
  10. package/dist/config/outConfig.d.ts +6 -7
  11. package/dist/config/outConfig.js +57 -106
  12. package/dist/config/performanceConfig.d.ts +9 -17
  13. package/dist/config/performanceConfig.js +18 -46
  14. package/dist/config/resolveConfig.d.ts +3 -11
  15. package/dist/config/resolveConfig.js +4 -32
  16. package/dist/config/serverConfig.d.ts +9 -17
  17. package/dist/config/serverConfig.js +22 -54
  18. package/dist/config/sourceConfig.d.ts +11 -12
  19. package/dist/config/sourceConfig.js +79 -154
  20. package/dist/config/toolsConfig.d.ts +10 -18
  21. package/dist/config/toolsConfig.js +36 -74
  22. package/dist/constants.d.ts +1 -1
  23. package/dist/constants.js +13 -44
  24. package/dist/dev.d.ts +23 -24
  25. package/dist/dev.js +32 -76
  26. package/dist/index.d.ts +6 -5
  27. package/dist/index.js +13 -29
  28. package/dist/requireHook.d.ts +1 -3
  29. package/dist/requireHook.js +27 -11
  30. package/dist/schema.d.ts +2 -2
  31. package/dist/schema.js +80 -195
  32. package/dist/server/compilerAdapter.d.ts +16 -0
  33. package/dist/server/compilerAdapter.js +7 -0
  34. package/dist/server/server.d.ts +13 -14
  35. package/dist/server/server.js +57 -107
  36. package/dist/types.d.ts +66 -73
  37. package/dist/types.js +19 -47
  38. package/dist/utils/checkConfig.js +13 -61
  39. package/dist/utils/getBrowsersList.d.ts +1 -2
  40. package/dist/utils/getBrowsersList.js +7 -36
  41. package/package.json +6 -5
@@ -0,0 +1,40 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esmMin = (fn, res, err) => () => {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = fn(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
14
+ };
15
+ var __exportAll = (all, no_symbols) => {
16
+ let target = {};
17
+ for (var name in all) __defProp(target, name, {
18
+ get: all[name],
19
+ enumerable: true
20
+ });
21
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
22
+ return target;
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
+ key = keys[i];
27
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
28
+ get: ((k) => from[k]).bind(null, key),
29
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
30
+ });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
35
+ value: mod,
36
+ enumerable: true
37
+ }) : target, mod));
38
+ exports.__esmMin = __esmMin;
39
+ exports.__exportAll = __exportAll;
40
+ exports.__toESM = __toESM;
package/dist/build.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { IConfig, MultiStats, Stats } from './types';
1
+ import { IConfig, MultiStats, Stats } from "./types.js";
2
2
  type IOpts = {
3
- cwd: string;
4
- rootDir?: string;
5
- entry: Record<string, string>;
6
- config: IConfig;
7
- onBuildComplete?: (opts: {
8
- err?: Error | null;
9
- stats?: Stats | MultiStats | any;
10
- isFirstCompile?: boolean;
11
- time?: number;
12
- }) => Promise<void>;
13
- clean?: boolean;
14
- watch?: boolean;
3
+ cwd: string;
4
+ rootDir?: string;
5
+ entry: Record<string, string>;
6
+ config: IConfig;
7
+ onBuildComplete?: (opts: {
8
+ err?: Error | null;
9
+ stats?: Stats | MultiStats | any;
10
+ isFirstCompile?: boolean;
11
+ time?: number;
12
+ }) => Promise<void>;
13
+ clean?: boolean;
14
+ watch?: boolean;
15
15
  };
16
16
  export declare function build(opts: IOpts): Promise<any>;
17
- export {};
package/dist/build.js CHANGED
@@ -1,122 +1,74 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/build.ts
30
- var build_exports = {};
31
- __export(build_exports, {
32
- build: () => build
33
- });
34
- module.exports = __toCommonJS(build_exports);
35
- var import_core = require("@rsbuild/core");
36
- var import_utils = require("@winner-fed/utils");
37
- var import_assert = __toESM(require("assert"));
38
- var import_types = require("./types");
39
- var import_checkConfig = require("./utils/checkConfig");
40
- var configModule = (0, import_utils.importLazy)(
41
- require.resolve("./config/config")
42
- );
43
- var statsJson = {};
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("./_virtual/_rolldown/runtime.js");
3
+ require("./types.js");
4
+ const require_utils_checkConfig = require("./utils/checkConfig.js");
5
+ let _rsbuild_core = require("@rsbuild/core");
6
+ let _winner_fed_utils = require("@winner-fed/utils");
7
+ let assert = require("assert");
8
+ assert = require_runtime.__toESM(assert);
9
+ const configModule = (0, _winner_fed_utils.importLazy)(require.resolve("./config/config"));
10
+ let statsJson = {};
44
11
  async function build(opts) {
45
- var _a, _b;
46
- (0, import_assert.default)(opts, "opts should be supplied");
47
- (0, import_checkConfig.checkConfig)(opts);
48
- const { cwd, onBuildComplete, config } = opts;
49
- const rsbuildConfig = await configModule.getRsbuildConfig({
50
- userConfig: opts.config,
51
- env: import_types.Env.production,
52
- extraBabelIncludes: (_a = opts.config) == null ? void 0 : _a.extraBabelIncludes,
53
- extraBabelExcludes: (_b = opts.config) == null ? void 0 : _b.extraBabelExcludes,
54
- ...opts
55
- });
56
- const rsbuild = await (0, import_core.createRsbuild)({
57
- cwd,
58
- rsbuildConfig
59
- });
60
- const isWatch = opts.watch ?? false;
61
- let isFirstCompile = true;
62
- const makeStats = () => {
63
- var _a2;
64
- return {
65
- compilation: {
66
- ...statsJson,
67
- // convert assets to [key: value] for compilation data
68
- assets: (_a2 = statsJson == null ? void 0 : statsJson.assets) == null ? void 0 : _a2.reduce(
69
- (acc, asset) => ({
70
- ...acc,
71
- [asset.name]: { size: asset.size }
72
- }),
73
- {}
74
- )
75
- },
76
- hasErrors: () => false
77
- };
78
- };
79
- try {
80
- rsbuild.onAfterBuild((params) => {
81
- var _a2, _b2, _c;
82
- const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c = (_b2 = params.stats) == null ? void 0 : _b2.stats) == null ? void 0 : _c[0] : params.stats;
83
- statsJson = s == null ? void 0 : s.toJson();
84
- if (isWatch && !isFirstCompile && onBuildComplete) {
85
- onBuildComplete({
86
- err: null,
87
- stats: makeStats(),
88
- isFirstCompile: false
89
- });
90
- }
91
- isFirstCompile = false;
92
- });
93
- await rsbuild.build({
94
- watch: isWatch
95
- });
96
- } catch (e) {
97
- console.error(e == null ? void 0 : e.message);
98
- throw new Error("Build with rsbuild failed.");
99
- }
100
- const { inspectConfig } = config;
101
- if (inspectConfig) {
102
- await rsbuild.inspectConfig({
103
- mode: import_types.Env.production,
104
- verbose: inspectConfig.verbose || false,
105
- outputPath: inspectConfig.outputPath,
106
- writeToDisk: true
107
- });
108
- }
109
- const stats = makeStats();
110
- if (onBuildComplete) {
111
- await onBuildComplete({
112
- err: null,
113
- stats,
114
- isFirstCompile: true
115
- });
116
- }
117
- return stats;
12
+ var _opts$config, _opts$config2, _opts$watch;
13
+ (0, assert.default)(opts, "opts should be supplied");
14
+ require_utils_checkConfig.checkConfig(opts);
15
+ const { cwd, onBuildComplete, config } = opts;
16
+ const rsbuildConfig = await configModule.getRsbuildConfig({
17
+ userConfig: opts.config,
18
+ env: "production",
19
+ extraBabelIncludes: (_opts$config = opts.config) === null || _opts$config === void 0 ? void 0 : _opts$config.extraBabelIncludes,
20
+ extraBabelExcludes: (_opts$config2 = opts.config) === null || _opts$config2 === void 0 ? void 0 : _opts$config2.extraBabelExcludes,
21
+ ...opts
22
+ });
23
+ const rsbuild = await (0, _rsbuild_core.createRsbuild)({
24
+ cwd,
25
+ rsbuildConfig
26
+ });
27
+ const isWatch = (_opts$watch = opts.watch) !== null && _opts$watch !== void 0 ? _opts$watch : false;
28
+ let isFirstCompile = true;
29
+ const makeStats = () => {
30
+ var _statsJson$assets;
31
+ return {
32
+ compilation: {
33
+ ...statsJson,
34
+ assets: statsJson === null || statsJson === void 0 || (_statsJson$assets = statsJson.assets) === null || _statsJson$assets === void 0 ? void 0 : _statsJson$assets.reduce((acc, asset) => ({
35
+ ...acc,
36
+ [asset.name]: { size: asset.size }
37
+ }), {})
38
+ },
39
+ hasErrors: () => false
40
+ };
41
+ };
42
+ try {
43
+ rsbuild.onAfterBuild((params) => {
44
+ var _params$stats, _params$stats2;
45
+ const s = ((_params$stats = params.stats) === null || _params$stats === void 0 ? void 0 : _params$stats.stats) ? (_params$stats2 = params.stats) === null || _params$stats2 === void 0 || (_params$stats2 = _params$stats2.stats) === null || _params$stats2 === void 0 ? void 0 : _params$stats2[0] : params.stats;
46
+ statsJson = s === null || s === void 0 ? void 0 : s.toJson();
47
+ if (isWatch && !isFirstCompile && onBuildComplete) onBuildComplete({
48
+ err: null,
49
+ stats: makeStats(),
50
+ isFirstCompile: false
51
+ });
52
+ isFirstCompile = false;
53
+ });
54
+ await rsbuild.build({ watch: isWatch });
55
+ } catch (e) {
56
+ console.error(e === null || e === void 0 ? void 0 : e.message);
57
+ throw new Error("Build with rsbuild failed.");
58
+ }
59
+ const { inspectConfig } = config;
60
+ if (inspectConfig) await rsbuild.inspectConfig({
61
+ mode: "production",
62
+ verbose: inspectConfig.verbose || false,
63
+ outputPath: inspectConfig.outputPath,
64
+ writeToDisk: true
65
+ });
66
+ const stats = makeStats();
67
+ if (onBuildComplete) await onBuildComplete({
68
+ err: null,
69
+ stats,
70
+ isFirstCompile: true
71
+ });
72
+ return stats;
118
73
  }
119
- // Annotate the CommonJS export names for ESM import in node:
120
- 0 && (module.exports = {
121
- build
122
- });
74
+ exports.build = build;
package/dist/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {}
package/dist/cli.js CHANGED
@@ -1,93 +1,63 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from))
10
- if (!__hasOwnProp.call(to, key) && key !== except)
11
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- }
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
-
24
- // src/cli.ts
25
- var import_esbuild = __toESM(require("@winner-fed/bundler-utils/compiled/esbuild"));
26
- var import_utils = require("@winner-fed/utils");
27
- var import_assert = __toESM(require("assert"));
28
- var import_fs = require("fs");
29
- var import_path = require("path");
30
- var import_build = require("./build");
31
- var import_dev = require("./dev");
32
- var args = (0, import_utils.yParser)(process.argv.slice(2), {});
33
- var command = args._[0];
34
- var cwd = process.cwd();
35
- var entry = (0, import_utils.tryPaths)([
36
- (0, import_path.join)(cwd, "src/index.tsx"),
37
- (0, import_path.join)(cwd, "src/index.ts"),
38
- (0, import_path.join)(cwd, "index.tsx"),
39
- (0, import_path.join)(cwd, "index.ts")
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.js");
2
+ const require_build = require("./build.js");
3
+ const require_dev = require("./dev.js");
4
+ const require_requireHook = require("./requireHook.js");
5
+ let _winner_fed_utils = require("@winner-fed/utils");
6
+ let assert = require("assert");
7
+ assert = require_runtime.__toESM(assert);
8
+ let _winner_fed_bundler_utils_compiled_esbuild = require("@winner-fed/bundler-utils/compiled/esbuild");
9
+ _winner_fed_bundler_utils_compiled_esbuild = require_runtime.__toESM(_winner_fed_bundler_utils_compiled_esbuild);
10
+ let fs = require("fs");
11
+ let path = require("path");
12
+ const args = (0, _winner_fed_utils.yParser)(process.argv.slice(2), {});
13
+ const command = args._[0];
14
+ const cwd = process.cwd();
15
+ const entry = (0, _winner_fed_utils.tryPaths)([
16
+ (0, path.join)(cwd, "src/index.tsx"),
17
+ (0, path.join)(cwd, "src/index.ts"),
18
+ (0, path.join)(cwd, "index.tsx"),
19
+ (0, path.join)(cwd, "index.ts")
40
20
  ]);
41
- var config = {};
42
- var configFile = (0, import_path.join)(cwd, args.config || "config.ts");
43
- import_utils.register.register({
44
- implementor: import_esbuild.default
45
- });
46
- import_utils.register.clearFiles();
47
- if ((0, import_fs.existsSync)(configFile)) {
48
- require("./requireHook");
49
- config = require(configFile).default;
21
+ let config = {};
22
+ const configFile = (0, path.join)(cwd, args.config || "config.ts");
23
+ _winner_fed_utils.register.register({ implementor: _winner_fed_bundler_utils_compiled_esbuild.default });
24
+ _winner_fed_utils.register.clearFiles();
25
+ if ((0, fs.existsSync)(configFile)) {
26
+ require_requireHook.init_requireHook();
27
+ config = require(configFile).default;
50
28
  }
51
29
  Object.assign(config, args);
52
- if (command === "build") {
53
- (async () => {
54
- process.env.NODE_ENV = "production";
55
- (0, import_assert.default)(entry, `Build failed: entry not found.`);
56
- try {
57
- await (0, import_build.build)({
58
- config,
59
- cwd,
60
- entry: {
61
- [getEntryKey(entry)]: entry
62
- }
63
- });
64
- } catch (e) {
65
- console.error(e);
66
- }
67
- })();
68
- } else if (command === "dev") {
69
- (async () => {
70
- process.env.NODE_ENV = "development";
71
- try {
72
- (0, import_assert.default)(entry, `Build failed: entry not found.`);
73
- await (0, import_dev.dev)({
74
- config,
75
- cwd,
76
- port: process.env.PORT,
77
- entry: {
78
- [getEntryKey(entry)]: entry
79
- }
80
- });
81
- } catch (e) {
82
- console.error(e);
83
- }
84
- })();
85
- } else {
86
- error(`Unsupported command ${command}.`);
87
- }
30
+ if (command === "build") (async () => {
31
+ process.env.NODE_ENV = "production";
32
+ (0, assert.default)(entry, `Build failed: entry not found.`);
33
+ try {
34
+ await require_build.build({
35
+ config,
36
+ cwd,
37
+ entry: { [getEntryKey(entry)]: entry }
38
+ });
39
+ } catch (e) {
40
+ console.error(e);
41
+ }
42
+ })();
43
+ else if (command === "dev") (async () => {
44
+ process.env.NODE_ENV = "development";
45
+ try {
46
+ (0, assert.default)(entry, `Build failed: entry not found.`);
47
+ await require_dev.dev({
48
+ config,
49
+ cwd,
50
+ port: process.env.PORT,
51
+ entry: { [getEntryKey(entry)]: entry }
52
+ });
53
+ } catch (e) {
54
+ console.error(e);
55
+ }
56
+ })();
57
+ else error(`Unsupported command ${command}.`);
88
58
  function error(msg) {
89
- console.error(import_utils.chalk.red(msg));
59
+ console.error(_winner_fed_utils.chalk.red(msg));
90
60
  }
91
- function getEntryKey(path) {
92
- return (0, import_path.basename)(path, (0, import_path.extname)(path));
61
+ function getEntryKey(path$1) {
62
+ return (0, path.basename)(path$1, (0, path.extname)(path$1));
93
63
  }
@@ -1,20 +1,30 @@
1
- import { RsbuildConfig, rspack } from '@rsbuild/core';
2
- import type { MaybePromise } from '@rsbuild/core/dist-types/types';
3
- import { Env, IBabelPlugin, IConfig } from '../types';
1
+ import { Env, IBabelPlugin, IConfig } from "../types.js";
2
+ import { RsbuildConfig, rspack } from "@rsbuild/core";
3
+ import { MaybePromise } from "@rsbuild/core/dist-types/types";
4
4
  export interface IOpts {
5
- cwd?: string;
6
- env?: Env;
7
- entry?: Record<string, string>;
8
- modifyRsbuildConfig?: {
9
- (memo: RsbuildConfig, args: {
10
- env: Env;
11
- rspack: typeof rspack;
12
- }): MaybePromise<RsbuildConfig>;
13
- };
14
- userConfig?: IConfig;
15
- extraBabelPlugins?: IBabelPlugin[];
16
- extraBabelIncludes?: Array<string | RegExp>;
17
- extraBabelExcludes?: Array<string | RegExp>;
18
- extraBabelPresets?: IBabelPlugin[];
5
+ cwd: string;
6
+ env: Env;
7
+ entry: Record<string, string>;
8
+ modifyRsbuildConfig?: {
9
+ (memo: RsbuildConfig, args: {
10
+ env: Env;
11
+ rspack: typeof rspack;
12
+ }): MaybePromise<RsbuildConfig>;
13
+ };
14
+ userConfig: IConfig;
15
+ beforeBabelPlugins?: IBabelPlugin[];
16
+ extraBabelPlugins?: IBabelPlugin[];
17
+ extraBabelIncludes?: Array<string | RegExp>;
18
+ extraBabelExcludes?: Array<string | RegExp>;
19
+ beforeBabelPresets?: IBabelPlugin[];
20
+ extraBabelPresets?: IBabelPlugin[];
19
21
  }
22
+ /**
23
+ * 聚合传入 bundler 的 babel 插件/preset(getBabelOpts 已把用户配置与
24
+ * addExtraBabel* 钩子合并进 opts.extraBabel*,此处只做排序与 falsy 过滤)
25
+ */
26
+ export declare function collectBabelExtras(opts: IOpts): {
27
+ plugins: IBabelPlugin[];
28
+ presets: IBabelPlugin[];
29
+ };
20
30
  export declare function getRsbuildConfig(opts: IOpts): Promise<RsbuildConfig>;