@nocobase/build 1.4.0-beta.1 → 1.4.0-beta.2

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.
@@ -31,14 +31,15 @@ __export(buildClient_exports, {
31
31
  buildLocale: () => buildLocale
32
32
  });
33
33
  module.exports = __toCommonJS(buildClient_exports);
34
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
34
35
  var import_fast_glob = __toESM(require("fast-glob"));
35
36
  var import_fs_extra = __toESM(require("fs-extra"));
36
37
  var import_path = __toESM(require("path"));
37
38
  var import_tsup = require("tsup");
38
39
  var import_vite = require("vite");
40
+ var import_vite_plugin_lib_inject_css = require("vite-plugin-lib-inject-css");
39
41
  var import_constant = require("./constant");
40
42
  var import_utils = require("./utils");
41
- var import_core = require("@rspack/core");
42
43
  async function buildClient(cwd, userConfig, sourcemap = false, log) {
43
44
  log("build client");
44
45
  const cwdWin = cwd.replaceAll(/\\/g, "/");
@@ -50,147 +51,38 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
50
51
  return true;
51
52
  };
52
53
  await buildClientEsm(cwd, userConfig, sourcemap, external, log);
54
+ await buildClientLib(cwd, userConfig, sourcemap, external, log);
53
55
  await buildLocale(cwd, userConfig, log);
54
56
  }
55
57
  function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
56
58
  log("build client esm");
57
59
  const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
58
60
  const outDir = import_path.default.resolve(cwd, "es");
59
- return (0, import_core.rspack)({
60
- entry: {
61
- index: entry
62
- },
63
- output: {
64
- path: outDir,
65
- library: {
66
- type: "module"
67
- },
68
- clean: true
69
- },
70
- target: ["es2015", "web"],
71
- mode: process.env.NODE_ENV === "production" ? "production" : "development",
72
- optimization: {
73
- minimize: process.env.NODE_ENV === "production",
74
- moduleIds: "deterministic",
75
- sideEffects: true
76
- },
77
- resolve: {
78
- tsConfig: import_path.default.join(process.cwd(), "tsconfig.json"),
79
- extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".less", ".css"]
80
- },
81
- module: {
82
- rules: [
83
- {
84
- test: /\.less$/,
85
- use: [
86
- { loader: "style-loader" },
87
- { loader: "css-loader" },
88
- { loader: require.resolve("less-loader") },
89
- {
90
- loader: "postcss-loader",
91
- options: {
92
- postcssOptions: {
93
- plugins: {
94
- "postcss-preset-env": {
95
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
96
- },
97
- autoprefixer: {}
98
- }
99
- }
100
- }
101
- }
102
- ],
103
- type: "javascript/auto"
104
- },
105
- {
106
- test: /\.css$/,
107
- use: [
108
- "style-loader",
109
- "css-loader",
110
- {
111
- loader: "postcss-loader",
112
- options: {
113
- postcssOptions: {
114
- plugins: {
115
- "postcss-preset-env": {
116
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
117
- },
118
- autoprefixer: {}
119
- }
120
- }
121
- }
122
- }
123
- ],
124
- type: "javascript/auto"
125
- },
126
- {
127
- test: /\.(png|jpe?g|gif)$/i,
128
- type: "asset"
129
- },
130
- {
131
- test: /\.svg$/i,
132
- issuer: /\.[jt]sx?$/,
133
- use: ["@svgr/webpack"]
134
- },
135
- {
136
- test: /\.jsx$/,
137
- exclude: /[\\/]node_modules[\\/]/,
138
- loader: "builtin:swc-loader",
139
- options: {
140
- sourceMap: true,
141
- jsc: {
142
- parser: {
143
- syntax: "ecmascript",
144
- jsx: true
145
- },
146
- target: "es5"
147
- }
148
- }
149
- },
150
- {
151
- test: /\.tsx$/,
152
- exclude: /[\\/]node_modules[\\/]/,
153
- loader: "builtin:swc-loader",
154
- options: {
155
- sourceMap: true,
156
- jsc: {
157
- parser: {
158
- syntax: "typescript",
159
- tsx: true
160
- },
161
- target: "es5"
162
- }
163
- }
61
+ return (0, import_vite.build)(
62
+ userConfig.modifyViteConfig({
63
+ mode: process.env.NODE_ENV || "production",
64
+ define: (0, import_utils.getEnvDefine)(),
65
+ build: {
66
+ minify: process.env.NODE_ENV === "production",
67
+ outDir,
68
+ cssCodeSplit: true,
69
+ emptyOutDir: true,
70
+ sourcemap,
71
+ lib: {
72
+ entry,
73
+ formats: ["es"],
74
+ fileName: "index"
164
75
  },
165
- {
166
- test: /\.ts$/,
167
- exclude: /[\\/]node_modules[\\/]/,
168
- loader: "builtin:swc-loader",
169
- options: {
170
- sourceMap: true,
171
- jsc: {
172
- parser: {
173
- syntax: "typescript"
174
- },
175
- target: "es5"
176
- }
177
- }
178
- }
179
- ]
180
- },
181
- externals: [
182
- function({ request }, callback) {
183
- if (external(request)) {
184
- return callback(null, true);
76
+ target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
77
+ rollupOptions: {
78
+ cache: true,
79
+ treeshake: true,
80
+ external
185
81
  }
186
- callback();
187
- }
188
- ],
189
- plugins: [
190
- new import_core.rspack.DefinePlugin((0, import_utils.getEnvDefine)())
191
- ],
192
- stats: "errors-warnings"
193
- });
82
+ },
83
+ plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_lib_inject_css.libInjectCss)()]
84
+ })
85
+ );
194
86
  }
195
87
  async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
196
88
  log("build client lib");
package/lib/buildEsm.js CHANGED
@@ -32,8 +32,8 @@ __export(buildEsm_exports, {
32
32
  module.exports = __toCommonJS(buildEsm_exports);
33
33
  var import_path = __toESM(require("path"));
34
34
  var import_utils = require("./utils");
35
+ var import_vite = require("vite");
35
36
  var import_fast_glob = __toESM(require("fast-glob"));
36
- var import_core = require("@rspack/core");
37
37
  const clientExt = ".{ts,tsx,js,jsx}";
38
38
  function getSingleEntry(file, cwd) {
39
39
  return import_fast_glob.default.sync([`${file}${clientExt}`], { cwd, absolute: true, onlyFiles: true })?.[0]?.replaceAll(/\\/g, "/");
@@ -67,134 +67,30 @@ function build(cwd, entry, outDir, userConfig, sourcemap = false, log) {
67
67
  }
68
68
  return true;
69
69
  };
70
- return (0, import_core.rspack)({
71
- entry: {
72
- index: entry
73
- },
74
- output: {
75
- path: outDir,
76
- library: {
77
- type: "module"
78
- },
79
- clean: true
80
- },
81
- target: ["node16"],
82
- mode: process.env.NODE_ENV === "production" ? "production" : "development",
83
- resolve: {
84
- tsConfig: import_path.default.join(process.cwd(), "tsconfig.json"),
85
- extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".less", ".css"]
86
- },
87
- module: {
88
- rules: [
89
- {
90
- test: /\.less$/,
91
- use: [
92
- { loader: "style-loader" },
93
- { loader: "css-loader" },
94
- { loader: require.resolve("less-loader") },
95
- {
96
- loader: "postcss-loader",
97
- options: {
98
- postcssOptions: {
99
- plugins: {
100
- "postcss-preset-env": {
101
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
102
- },
103
- autoprefixer: {}
104
- }
105
- }
106
- }
107
- }
108
- ],
109
- type: "javascript/auto"
70
+ return (0, import_vite.build)(
71
+ userConfig.modifyViteConfig({
72
+ mode: process.env.NODE_ENV || "production",
73
+ define: (0, import_utils.getEnvDefine)(),
74
+ build: {
75
+ minify: false,
76
+ outDir,
77
+ cssCodeSplit: true,
78
+ emptyOutDir: true,
79
+ sourcemap,
80
+ lib: {
81
+ entry,
82
+ formats: ["es"],
83
+ fileName: "index"
110
84
  },
111
- {
112
- test: /\.css$/,
113
- use: [
114
- "style-loader",
115
- "css-loader",
116
- {
117
- loader: "postcss-loader",
118
- options: {
119
- postcssOptions: {
120
- plugins: {
121
- "postcss-preset-env": {
122
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
123
- },
124
- autoprefixer: {}
125
- }
126
- }
127
- }
128
- }
129
- ],
130
- type: "javascript/auto"
131
- },
132
- {
133
- test: /\.(png|jpe?g|gif)$/i,
134
- type: "asset"
135
- },
136
- {
137
- test: /\.svg$/i,
138
- issuer: /\.[jt]sx?$/,
139
- use: ["@svgr/webpack"]
140
- },
141
- {
142
- test: /\.jsx$/,
143
- exclude: /[\\/]node_modules[\\/]/,
144
- loader: "builtin:swc-loader",
145
- options: {
146
- sourceMap: true,
147
- jsc: {
148
- parser: {
149
- syntax: "ecmascript",
150
- jsx: true
151
- },
152
- target: "es5"
153
- }
154
- }
155
- },
156
- {
157
- test: /\.tsx$/,
158
- exclude: /[\\/]node_modules[\\/]/,
159
- loader: "builtin:swc-loader",
160
- options: {
161
- sourceMap: true,
162
- jsc: {
163
- parser: {
164
- syntax: "typescript",
165
- tsx: true
166
- },
167
- target: "es5"
168
- }
169
- }
170
- },
171
- {
172
- test: /\.ts$/,
173
- exclude: /[\\/]node_modules[\\/]/,
174
- loader: "builtin:swc-loader",
175
- options: {
176
- sourceMap: true,
177
- jsc: {
178
- parser: {
179
- syntax: "typescript"
180
- },
181
- target: "es5"
182
- }
183
- }
184
- }
185
- ]
186
- },
187
- externals: [
188
- function({ request }, callback) {
189
- if (external(request)) {
190
- return callback(null, true);
85
+ target: ["node16"],
86
+ rollupOptions: {
87
+ cache: true,
88
+ treeshake: true,
89
+ external
191
90
  }
192
- callback();
193
91
  }
194
- ],
195
- plugins: [new import_core.rspack.DefinePlugin((0, import_utils.getEnvDefine)())],
196
- stats: "errors-warnings"
197
- });
92
+ })
93
+ );
198
94
  }
199
95
  // Annotate the CommonJS export names for ESM import in node:
200
96
  0 && (module.exports = {
@@ -36,12 +36,14 @@ __export(buildPlugin_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(buildPlugin_exports);
38
38
  var import_ncc = __toESM(require("@vercel/ncc"));
39
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
39
40
  var import_chalk = __toESM(require("chalk"));
40
41
  var import_fast_glob = __toESM(require("fast-glob"));
41
42
  var import_fs_extra = __toESM(require("fs-extra"));
42
43
  var import_path = __toESM(require("path"));
43
44
  var import_tsup = require("tsup");
44
- var import_core = require("@rspack/core");
45
+ var import_vite = require("vite");
46
+ var import_vite_plugin_css_injected_by_js = __toESM(require("vite-plugin-css-injected-by-js"));
45
47
  var import_constant = require("./constant");
46
48
  var import_utils = require("./utils");
47
49
  var import_buildPluginUtils = require("./utils/buildPluginUtils");
@@ -131,8 +133,7 @@ const external = [
131
133
  "@emotion/css",
132
134
  "ahooks",
133
135
  "lodash",
134
- "china-division",
135
- "file-saver"
136
+ "china-division"
136
137
  ];
137
138
  const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
138
139
  const target_dir = "dist";
@@ -186,9 +187,7 @@ async function buildServerDeps(cwd, serverFiles, log) {
186
187
  if (excludePackages.length) {
187
188
  tips.push(`These packages ${import_chalk.default.yellow(excludePackages.join(", "))} will be ${import_chalk.default.italic("exclude")}.`);
188
189
  }
189
- tips.push(
190
- `For more information, please refer to: ${import_chalk.default.blue("https://docs.nocobase.com/development/others/deps")}.`
191
- );
190
+ tips.push(`For more information, please refer to: ${import_chalk.default.blue("https://docs.nocobase.com/development/deps")}.`);
192
191
  log(tips.join(" "));
193
192
  if (!includePackages.length) return;
194
193
  const deps = (0, import_getDepsConfig.getDepsConfig)(cwd, outDir, includePackages, external);
@@ -288,164 +287,48 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
288
287
  const outDir = import_path.default.join(cwd, target_dir, "client");
289
288
  const globals = excludePackages.reduce((prev, curr) => {
290
289
  if (curr.startsWith("@nocobase")) {
291
- prev[`${curr}/client`] = `${curr}/client`;
290
+ prev[`${curr}/client`] = curr;
292
291
  }
293
292
  prev[curr] = curr;
294
293
  return prev;
295
294
  }, {});
296
- const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
295
+ const entry = import_fast_glob.default.globSync("src/client/index.{ts,tsx,js,jsx}", { absolute: true, cwd });
297
296
  const outputFileName = "index.js";
298
- const compiler = (0, import_core.rspack)({
299
- mode: "production",
300
- // mode: "development",
301
- context: cwd,
302
- entry: "./src/client/" + entry[0],
303
- target: ["web", "es5"],
304
- output: {
305
- path: outDir,
306
- filename: outputFileName,
307
- publicPath: `/static/plugins/${packageJson.name}/dist/client/`,
308
- clean: true,
309
- library: {
310
- name: packageJson.name,
311
- type: "umd",
312
- umdNamedDefine: true
313
- }
314
- },
315
- resolve: {
316
- tsConfig: import_path.default.join(process.cwd(), "tsconfig.json"),
317
- extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".less", ".css"]
318
- },
319
- module: {
320
- rules: [
321
- {
322
- test: /\.less$/,
323
- use: [
324
- { loader: "style-loader" },
325
- { loader: "css-loader" },
326
- { loader: require.resolve("less-loader") },
327
- {
328
- loader: "postcss-loader",
329
- options: {
330
- postcssOptions: {
331
- plugins: {
332
- "postcss-preset-env": {
333
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
334
- },
335
- autoprefixer: {}
336
- }
337
- }
338
- }
339
- }
340
- ],
341
- type: "javascript/auto"
342
- },
343
- {
344
- test: /\.css$/,
345
- use: [
346
- "style-loader",
347
- "css-loader",
348
- {
349
- loader: "postcss-loader",
350
- options: {
351
- postcssOptions: {
352
- plugins: {
353
- "postcss-preset-env": {
354
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
355
- },
356
- autoprefixer: {}
357
- }
358
- }
359
- }
360
- }
361
- ],
362
- type: "javascript/auto"
363
- },
364
- {
365
- test: /\.(png|jpe?g|gif)$/i,
366
- type: "asset"
367
- },
368
- {
369
- test: /\.svg$/i,
370
- issuer: /\.[jt]sx?$/,
371
- use: ["@svgr/webpack"]
372
- },
373
- {
374
- test: /\.jsx$/,
375
- exclude: /[\\/]node_modules[\\/]/,
376
- loader: "builtin:swc-loader",
377
- options: {
378
- sourceMap: true,
379
- jsc: {
380
- parser: {
381
- syntax: "ecmascript",
382
- jsx: true
383
- },
384
- target: "es5"
385
- }
386
- }
297
+ await (0, import_vite.build)(
298
+ userConfig.modifyViteConfig({
299
+ mode: process.env.NODE_ENV || "production",
300
+ define: (0, import_utils.getEnvDefine)(),
301
+ logLevel: "warn",
302
+ build: {
303
+ minify: process.env.NODE_ENV === "production",
304
+ outDir,
305
+ cssCodeSplit: false,
306
+ emptyOutDir: true,
307
+ sourcemap,
308
+ lib: {
309
+ entry,
310
+ formats: ["umd"],
311
+ name: packageJson.name,
312
+ fileName: () => outputFileName
387
313
  },
388
- {
389
- test: /\.tsx$/,
390
- exclude: /[\\/]node_modules[\\/]/,
391
- loader: "builtin:swc-loader",
392
- options: {
393
- sourceMap: true,
394
- jsc: {
395
- parser: {
396
- syntax: "typescript",
397
- tsx: true
398
- },
399
- target: "es5"
400
- }
401
- }
402
- },
403
- {
404
- test: /\.ts$/,
405
- exclude: /[\\/]node_modules[\\/]/,
406
- loader: "builtin:swc-loader",
407
- options: {
408
- sourceMap: true,
409
- jsc: {
410
- parser: {
411
- syntax: "typescript"
412
- },
413
- target: "es5"
314
+ target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
315
+ rollupOptions: {
316
+ cache: true,
317
+ external: [...Object.keys(globals), "react", "react/jsx-runtime"],
318
+ output: {
319
+ exports: "named",
320
+ globals: {
321
+ react: "React",
322
+ "react/jsx-runtime": "jsxRuntime",
323
+ ...globals
414
324
  }
415
325
  }
416
326
  }
417
- ]
418
- },
419
- plugins: [
420
- new import_core.rspack.DefinePlugin({
421
- "process.env.NODE_ENV": JSON.stringify("production")
422
- })
423
- ],
424
- node: {
425
- global: true
426
- },
427
- externals: {
428
- react: "React",
429
- lodash: "lodash",
430
- // 'react/jsx-runtime': 'jsxRuntime',
431
- ...globals
432
- },
433
- stats: "errors-warnings"
434
- });
435
- return new Promise((resolve, reject) => {
436
- compiler.run((err, stats) => {
437
- const compilationErrors = stats?.compilation.errors;
438
- const infos = stats.toString({
439
- colors: true
440
- });
441
- if (err || compilationErrors?.length) {
442
- reject(err || infos);
443
- return;
444
- }
445
- console.log(infos);
446
- resolve(null);
447
- });
448
- });
327
+ },
328
+ plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_css_injected_by_js.default)({ styleId: packageJson.name })]
329
+ })
330
+ );
331
+ (0, import_buildPluginUtils.checkFileSize)(outDir, log);
449
332
  }
450
333
  async function buildPlugin(cwd, userConfig, sourcemap, log) {
451
334
  await buildPluginClient(cwd, userConfig, sourcemap, log);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/build",
3
- "version": "1.4.0-beta.1",
3
+ "version": "1.4.0-beta.2",
4
4
  "description": "Library build tool based on rollup.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -45,5 +45,5 @@
45
45
  "scripts": {
46
46
  "build": "tsup"
47
47
  },
48
- "gitHead": "1ece4e558ba445088dbb658bd458eb0004295326"
48
+ "gitHead": "d5b141a3cd197a3165d69306b99135ea0c7e4aa2"
49
49
  }