@nocobase/build 1.5.0-alpha.5 → 1.5.0-beta.1

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/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 = {
@@ -35,13 +35,15 @@ __export(buildPlugin_exports, {
35
35
  writeExternalPackageVersion: () => writeExternalPackageVersion
36
36
  });
37
37
  module.exports = __toCommonJS(buildPlugin_exports);
38
- var import_core = require("@rspack/core");
39
38
  var import_ncc = __toESM(require("@vercel/ncc"));
39
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
40
40
  var import_chalk = __toESM(require("chalk"));
41
41
  var import_fast_glob = __toESM(require("fast-glob"));
42
42
  var import_fs_extra = __toESM(require("fs-extra"));
43
43
  var import_path = __toESM(require("path"));
44
44
  var import_tsup = require("tsup");
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");
@@ -60,10 +62,8 @@ const external = [
60
62
  "@nocobase/database",
61
63
  "@nocobase/data-source-manager",
62
64
  "@nocobase/evaluators",
63
- "@nocobase/lock-manager",
64
65
  "@nocobase/logger",
65
66
  "@nocobase/resourcer",
66
- "@nocobase/telemetry",
67
67
  "@nocobase/sdk",
68
68
  "@nocobase/server",
69
69
  "@nocobase/test",
@@ -133,8 +133,7 @@ const external = [
133
133
  "@emotion/css",
134
134
  "ahooks",
135
135
  "lodash",
136
- "china-division",
137
- "file-saver"
136
+ "china-division"
138
137
  ];
139
138
  const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
140
139
  const target_dir = "dist";
@@ -188,9 +187,7 @@ async function buildServerDeps(cwd, serverFiles, log) {
188
187
  if (excludePackages.length) {
189
188
  tips.push(`These packages ${import_chalk.default.yellow(excludePackages.join(", "))} will be ${import_chalk.default.italic("exclude")}.`);
190
189
  }
191
- tips.push(
192
- `For more information, please refer to: ${import_chalk.default.blue("https://docs.nocobase.com/development/others/deps")}.`
193
- );
190
+ tips.push(`For more information, please refer to: ${import_chalk.default.blue("https://docs.nocobase.com/development/deps")}.`);
194
191
  log(tips.join(" "));
195
192
  if (!includePackages.length) return;
196
193
  const deps = (0, import_getDepsConfig.getDepsConfig)(cwd, outDir, includePackages, external);
@@ -290,164 +287,48 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
290
287
  const outDir = import_path.default.join(cwd, target_dir, "client");
291
288
  const globals = excludePackages.reduce((prev, curr) => {
292
289
  if (curr.startsWith("@nocobase")) {
293
- prev[`${curr}/client`] = `${curr}/client`;
290
+ prev[`${curr}/client`] = curr;
294
291
  }
295
292
  prev[curr] = curr;
296
293
  return prev;
297
294
  }, {});
298
- 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 });
299
296
  const outputFileName = "index.js";
300
- const compiler = (0, import_core.rspack)({
301
- mode: "production",
302
- // mode: "development",
303
- context: cwd,
304
- entry: "./src/client/" + entry[0],
305
- target: ["web", "es5"],
306
- output: {
307
- path: outDir,
308
- filename: outputFileName,
309
- publicPath: `/static/plugins/${packageJson.name}/dist/client/`,
310
- clean: true,
311
- library: {
312
- name: packageJson.name,
313
- type: "umd",
314
- umdNamedDefine: true
315
- }
316
- },
317
- resolve: {
318
- tsConfig: import_path.default.join(process.cwd(), "tsconfig.json"),
319
- extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".less", ".css"]
320
- },
321
- module: {
322
- rules: [
323
- {
324
- test: /\.less$/,
325
- use: [
326
- { loader: "style-loader" },
327
- { loader: "css-loader" },
328
- { loader: require.resolve("less-loader") },
329
- {
330
- loader: "postcss-loader",
331
- options: {
332
- postcssOptions: {
333
- plugins: {
334
- "postcss-preset-env": {
335
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
336
- },
337
- autoprefixer: {}
338
- }
339
- }
340
- }
341
- }
342
- ],
343
- type: "javascript/auto"
344
- },
345
- {
346
- test: /\.css$/,
347
- use: [
348
- "style-loader",
349
- "css-loader",
350
- {
351
- loader: "postcss-loader",
352
- options: {
353
- postcssOptions: {
354
- plugins: {
355
- "postcss-preset-env": {
356
- browsers: ["last 2 versions", "> 1%", "cover 99.5%", "not dead"]
357
- },
358
- autoprefixer: {}
359
- }
360
- }
361
- }
362
- }
363
- ],
364
- type: "javascript/auto"
365
- },
366
- {
367
- test: /\.(png|jpe?g|gif)$/i,
368
- type: "asset"
369
- },
370
- {
371
- test: /\.svg$/i,
372
- issuer: /\.[jt]sx?$/,
373
- use: ["@svgr/webpack"]
374
- },
375
- {
376
- test: /\.jsx$/,
377
- exclude: /[\\/]node_modules[\\/]/,
378
- loader: "builtin:swc-loader",
379
- options: {
380
- sourceMap: true,
381
- jsc: {
382
- parser: {
383
- syntax: "ecmascript",
384
- jsx: true
385
- },
386
- target: "es5"
387
- }
388
- }
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
389
313
  },
390
- {
391
- test: /\.tsx$/,
392
- exclude: /[\\/]node_modules[\\/]/,
393
- loader: "builtin:swc-loader",
394
- options: {
395
- sourceMap: true,
396
- jsc: {
397
- parser: {
398
- syntax: "typescript",
399
- tsx: true
400
- },
401
- target: "es5"
402
- }
403
- }
404
- },
405
- {
406
- test: /\.ts$/,
407
- exclude: /[\\/]node_modules[\\/]/,
408
- loader: "builtin:swc-loader",
409
- options: {
410
- sourceMap: true,
411
- jsc: {
412
- parser: {
413
- syntax: "typescript"
414
- },
415
- 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
416
324
  }
417
325
  }
418
326
  }
419
- ]
420
- },
421
- plugins: [
422
- new import_core.rspack.DefinePlugin({
423
- "process.env.NODE_ENV": JSON.stringify("production")
424
- })
425
- ],
426
- node: {
427
- global: true
428
- },
429
- externals: {
430
- react: "React",
431
- lodash: "lodash",
432
- // 'react/jsx-runtime': 'jsxRuntime',
433
- ...globals
434
- },
435
- stats: "errors-warnings"
436
- });
437
- return new Promise((resolve, reject) => {
438
- compiler.run((err, stats) => {
439
- const compilationErrors = stats?.compilation.errors;
440
- const infos = stats.toString({
441
- colors: true
442
- });
443
- if (err || compilationErrors?.length) {
444
- reject(err || infos);
445
- return;
446
- }
447
- console.log(infos);
448
- resolve(null);
449
- });
450
- });
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);
451
332
  }
452
333
  async function buildPlugin(cwd, userConfig, sourcemap, log) {
453
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.5.0-alpha.5",
3
+ "version": "1.5.0-beta.1",
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": "8d24e8d2c0f3f57ceaa271438fd93db2b4150011"
48
+ "gitHead": "10c6f1f3d90e91f3aabfa80449c7ef062e90f6af"
49
49
  }