@winner-fed/bundler-rsbuild 0.14.5 → 0.14.6-alpha.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.
package/dist/build.js CHANGED
@@ -42,13 +42,15 @@ var configModule = (0, import_utils.importLazy)(
42
42
  );
43
43
  var statsJson = {};
44
44
  async function build(opts) {
45
- var _a;
45
+ var _a, _b, _c;
46
46
  (0, import_assert.default)(opts, "opts should be supplied");
47
47
  (0, import_checkConfig.checkConfig)(opts);
48
48
  const { cwd, onBuildComplete, config } = opts;
49
49
  const rsbuildConfig = await configModule.getRsbuildConfig({
50
50
  userConfig: opts.config,
51
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,
52
54
  ...opts
53
55
  });
54
56
  const rsbuild = await (0, import_core.createRsbuild)({
@@ -57,8 +59,8 @@ async function build(opts) {
57
59
  });
58
60
  try {
59
61
  rsbuild.onAfterBuild((params) => {
60
- var _a2, _b, _c;
61
- const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c = (_b = params.stats) == null ? void 0 : _b.stats) == null ? void 0 : _c[0] : params.stats;
62
+ var _a2, _b2, _c2;
63
+ const s = ((_a2 = params.stats) == null ? void 0 : _a2.stats) ? (_c2 = (_b2 = params.stats) == null ? void 0 : _b2.stats) == null ? void 0 : _c2[0] : params.stats;
62
64
  statsJson = s == null ? void 0 : s.toJson();
63
65
  });
64
66
  await rsbuild.build({
@@ -81,7 +83,7 @@ async function build(opts) {
81
83
  compilation: {
82
84
  ...statsJson,
83
85
  // convert assets to [key: value] for compilation data
84
- assets: (_a = statsJson == null ? void 0 : statsJson.assets) == null ? void 0 : _a.reduce(
86
+ assets: (_c = statsJson == null ? void 0 : statsJson.assets) == null ? void 0 : _c.reduce(
85
87
  (acc, asset) => ({
86
88
  ...acc,
87
89
  [asset.name]: { size: asset.size }
@@ -14,6 +14,7 @@ export interface IOpts {
14
14
  userConfig?: IConfig;
15
15
  extraBabelPlugins?: IBabelPlugin[];
16
16
  extraBabelIncludes?: Array<string | RegExp>;
17
+ extraBabelExcludes?: Array<string | RegExp>;
17
18
  extraBabelPresets?: IBabelPlugin[];
18
19
  }
19
20
  export declare function getRsbuildConfig(opts: IOpts): Promise<RsbuildConfig>;
@@ -59,6 +59,14 @@ async function getRsbuildConfig(opts) {
59
59
  const serverConfig = (0, import_serverConfig.getServerConfig)(opts);
60
60
  const toolsConfig = (0, import_toolsConfig.getToolsConfig)(opts);
61
61
  const performanceConfig = (0, import_performanceConfig.getPerformanceConfig)(opts);
62
+ const babelIncludePatterns = [
63
+ /\.(?:jsx|tsx|js)$/,
64
+ ...sourceConfig.include || []
65
+ ];
66
+ const babelExcludePatterns = [
67
+ /[\\/]node_modules[\\/]/,
68
+ ...sourceConfig.exclude || []
69
+ ];
62
70
  let rsbuildConfig = {
63
71
  source: sourceConfig,
64
72
  resolve: resolveConfig,
@@ -96,8 +104,8 @@ async function getRsbuildConfig(opts) {
96
104
  stylusOptions: (userConfig == null ? void 0 : userConfig.stylusLoader) || {}
97
105
  }),
98
106
  (0, import_plugin_babel.pluginBabel)({
99
- include: /\.(?:jsx|tsx|js)$/,
100
- exclude: /[\\/]node_modules[\\/]/,
107
+ include: babelIncludePatterns,
108
+ exclude: babelExcludePatterns,
101
109
  babelLoaderOptions: ({}, { addPlugins, addPresets }) => {
102
110
  addPlugins([...(userConfig == null ? void 0 : userConfig.extraBabelPlugins) || []]);
103
111
  addPresets([...(userConfig == null ? void 0 : userConfig.extraBabelPresets) || []]);
@@ -86,7 +86,7 @@ function getSourceConfig(opts) {
86
86
  }
87
87
  try {
88
88
  if (p.startsWith("./")) {
89
- return require.resolve(p, { paths: [cwd] });
89
+ return (0, import_path.resolve)(cwd, p);
90
90
  }
91
91
  return (0, import_path.dirname)(
92
92
  import_utils.resolve.sync(`${p}/package.json`, {
@@ -106,11 +106,43 @@ function getSourceConfig(opts) {
106
106
  }
107
107
  });
108
108
  }
109
+ let extraExcludes = [];
110
+ if (Array.isArray(userConfig == null ? void 0 : userConfig.extraBabelExcludes) && (userConfig == null ? void 0 : userConfig.extraBabelExcludes.length)) {
111
+ extraExcludes = userConfig.extraBabelExcludes.map((p) => {
112
+ if (import_utils.lodash.isRegExp(p)) {
113
+ return p;
114
+ }
115
+ if ((0, import_path.isAbsolute)(p)) {
116
+ return p;
117
+ }
118
+ try {
119
+ if (p.startsWith("./")) {
120
+ return require.resolve(p, { paths: [cwd] });
121
+ }
122
+ return (0, import_path.dirname)(
123
+ import_utils.resolve.sync(`${p}/package.json`, {
124
+ basedir: cwd,
125
+ // same behavior as webpack, to ensure `include` paths matched
126
+ // ref: https://webpack.js.org/configuration/resolve/#resolvesymlinks
127
+ preserveSymlinks: false
128
+ })
129
+ );
130
+ } catch (e) {
131
+ if (e.code === "MODULE_NOT_FOUND") {
132
+ throw new Error("Cannot resolve extraBabelExcludes: " + p, {
133
+ cause: e
134
+ });
135
+ }
136
+ throw e;
137
+ }
138
+ });
139
+ }
109
140
  return {
110
141
  define: resolveDefine(opts),
111
142
  entry,
112
143
  tsconfigPath,
113
- include: [...extraIncludes]
144
+ include: [...extraIncludes],
145
+ exclude: [...extraExcludes]
114
146
  };
115
147
  }
116
148
  // Annotate the CommonJS export names for ESM import in node:
package/dist/dev.js CHANGED
@@ -41,6 +41,7 @@ var configModule = (0, import_utils.importLazy)(
41
41
  require.resolve("./config/config")
42
42
  );
43
43
  async function dev(opts) {
44
+ var _a, _b;
44
45
  (0, import_assert.default)(opts, "opts should be supplied");
45
46
  (0, import_checkConfig.checkConfig)(opts);
46
47
  const rsbuildConfig = await configModule.getRsbuildConfig({
@@ -54,6 +55,8 @@ async function dev(opts) {
54
55
  ...opts.beforeBabelPresets || [],
55
56
  ...opts.extraBabelPresets || []
56
57
  ],
58
+ extraBabelIncludes: (_a = opts.config) == null ? void 0 : _a.extraBabelIncludes,
59
+ extraBabelExcludes: (_b = opts.config) == null ? void 0 : _b.extraBabelExcludes,
57
60
  ...opts
58
61
  });
59
62
  await (0, import_server.createServer)({
package/dist/schema.js CHANGED
@@ -75,6 +75,7 @@ function getSchemas() {
75
75
  zod.string(),
76
76
  zod.function()
77
77
  ]),
78
+ extraBabelExcludes: ({ zod }) => zod.array(zod.union([zod.string(), zod.instanceof(RegExp)])),
78
79
  extraBabelIncludes: ({ zod }) => zod.array(zod.union([zod.string(), zod.instanceof(RegExp)])),
79
80
  extraBabelPlugins: ({ zod }) => zod.array(zod.union([zod.string(), zod.array(zod.any())])),
80
81
  extraBabelPresets: ({ zod }) => zod.array(zod.union([zod.string(), zod.array(zod.any())])),
package/dist/types.d.ts CHANGED
@@ -53,6 +53,7 @@ export interface IConfig {
53
53
  extraBabelPlugins?: IBabelPlugin[];
54
54
  extraBabelPresets?: IBabelPlugin[];
55
55
  extraBabelIncludes?: Array<string | RegExp>;
56
+ extraBabelExcludes?: Array<string | RegExp>;
56
57
  extraPostCSSPlugins?: any[];
57
58
  hash?: boolean;
58
59
  manifest?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winner-fed/bundler-rsbuild",
3
- "version": "0.14.5",
3
+ "version": "0.14.6-alpha.0",
4
4
  "description": "@winner-fed/bundler-rsbuild",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -19,8 +19,8 @@
19
19
  "@rsbuild/plugin-sass": "1.3.2",
20
20
  "@rsbuild/plugin-stylus": "1.1.1",
21
21
  "@rsbuild/plugin-type-check": "1.2.1",
22
- "@winner-fed/bundler-utils": "0.14.5",
23
- "@winner-fed/utils": "0.14.5"
22
+ "@winner-fed/bundler-utils": "0.14.6-alpha.0",
23
+ "@winner-fed/utils": "0.14.6-alpha.0"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"