@nocobase/build 2.1.0-alpha.10 → 2.1.0-alpha.12
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/buildClient.js +113 -53
- package/lib/buildPlugin.js +66 -26
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +28 -8
- package/lib/utils/utils.js +1 -1
- package/package.json +6 -4
package/lib/buildClient.js
CHANGED
|
@@ -31,13 +31,14 @@ __export(buildClient_exports, {
|
|
|
31
31
|
buildLocale: () => buildLocale
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(buildClient_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_core = require("@rsbuild/core");
|
|
35
|
+
var import_plugin_less = require("@rsbuild/plugin-less");
|
|
36
|
+
var import_plugin_react = require("@rsbuild/plugin-react");
|
|
37
|
+
var import_plugin_svgr = require("@rsbuild/plugin-svgr");
|
|
35
38
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
36
39
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
37
40
|
var import_path = __toESM(require("path"));
|
|
38
41
|
var import_tsup = require("tsup");
|
|
39
|
-
var import_vite = require("vite");
|
|
40
|
-
var import_vite_plugin_lib_inject_css = require("vite-plugin-lib-inject-css");
|
|
41
42
|
var import_constant = require("./constant");
|
|
42
43
|
var import_utils = require("./utils");
|
|
43
44
|
async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
@@ -45,7 +46,7 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
|
45
46
|
const cwdWin = cwd.replaceAll(/\\/g, "/");
|
|
46
47
|
const cwdUnix = cwd.replaceAll(/\//g, "\\");
|
|
47
48
|
const external = function(id) {
|
|
48
|
-
if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
|
|
49
|
+
if (!id || import_path.default.isAbsolute(id) || id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
|
|
49
50
|
return false;
|
|
50
51
|
}
|
|
51
52
|
return true;
|
|
@@ -54,35 +55,12 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
|
54
55
|
await buildClientLib(cwd, userConfig, sourcemap, external, log);
|
|
55
56
|
await buildLocale(cwd, userConfig, log);
|
|
56
57
|
}
|
|
57
|
-
function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
|
|
58
|
+
async function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
|
|
58
59
|
log("build client esm");
|
|
59
60
|
const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
|
|
60
61
|
const outDir = import_path.default.resolve(cwd, "es");
|
|
61
|
-
|
|
62
|
-
|
|
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"
|
|
75
|
-
},
|
|
76
|
-
target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
|
|
77
|
-
rollupOptions: {
|
|
78
|
-
cache: true,
|
|
79
|
-
treeshake: true,
|
|
80
|
-
external
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_lib_inject_css.libInjectCss)()]
|
|
84
|
-
})
|
|
85
|
-
);
|
|
62
|
+
await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "esm");
|
|
63
|
+
await injectEntryStyleReference(import_path.default.join(outDir, "index.mjs"), 'import "./index.css";');
|
|
86
64
|
}
|
|
87
65
|
async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
|
|
88
66
|
log("build client lib");
|
|
@@ -91,32 +69,114 @@ async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
|
|
|
91
69
|
const entry = import_path.default.join(esDir, "index.ts");
|
|
92
70
|
import_fs_extra.default.removeSync(entry);
|
|
93
71
|
import_fs_extra.default.linkSync(import_path.default.join(cwd, "es/index.mjs"), entry);
|
|
94
|
-
|
|
95
|
-
userConfig
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
72
|
+
try {
|
|
73
|
+
await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "cjs");
|
|
74
|
+
} finally {
|
|
75
|
+
import_fs_extra.default.removeSync(entry);
|
|
76
|
+
}
|
|
77
|
+
await injectEntryStyleReference(import_path.default.join(outDir, "index.js"), 'require("./index.css");');
|
|
78
|
+
}
|
|
79
|
+
async function buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, format) {
|
|
80
|
+
const config = createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format);
|
|
81
|
+
const rsbuild = await (0, import_core.createRsbuild)({
|
|
82
|
+
cwd,
|
|
83
|
+
config: userConfig.modifyRsbuildConfig?.(config) ?? config
|
|
84
|
+
});
|
|
85
|
+
const result = await rsbuild.build();
|
|
86
|
+
await result.close();
|
|
87
|
+
}
|
|
88
|
+
function createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format) {
|
|
89
|
+
return {
|
|
90
|
+
plugins: [(0, import_plugin_react.pluginReact)(), (0, import_plugin_less.pluginLess)(), (0, import_plugin_svgr.pluginSvgr)()],
|
|
91
|
+
source: {
|
|
92
|
+
entry: {
|
|
93
|
+
index: {
|
|
94
|
+
import: entry,
|
|
95
|
+
html: false
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
tsconfigPath: import_path.default.join(cwd, "tsconfig.json"),
|
|
99
|
+
define: (0, import_utils.getEnvDefine)(),
|
|
100
|
+
decorators: {
|
|
101
|
+
version: "legacy"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
output: {
|
|
105
|
+
target: "web",
|
|
106
|
+
distPath: {
|
|
107
|
+
root: outDir,
|
|
108
|
+
js: ".",
|
|
109
|
+
jsAsync: ".",
|
|
110
|
+
css: ".",
|
|
111
|
+
cssAsync: ".",
|
|
112
|
+
svg: ".",
|
|
113
|
+
font: ".",
|
|
114
|
+
image: ".",
|
|
115
|
+
media: ".",
|
|
116
|
+
assets: "."
|
|
99
117
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
filename: {
|
|
119
|
+
js: format === "esm" ? "[name].mjs" : "[name].js",
|
|
120
|
+
css: "[name].css",
|
|
121
|
+
svg: "[name][ext][query]",
|
|
122
|
+
font: "[name][ext][query]",
|
|
123
|
+
image: "[name][ext][query]",
|
|
124
|
+
media: "[name][ext][query]",
|
|
125
|
+
assets: "[name][ext][query]"
|
|
126
|
+
},
|
|
127
|
+
cleanDistPath: true,
|
|
128
|
+
sourceMap: sourcemap,
|
|
129
|
+
minify: process.env.NODE_ENV === "production",
|
|
130
|
+
emitCss: true,
|
|
131
|
+
externals: [
|
|
132
|
+
function({ request }, callback) {
|
|
133
|
+
if (request && external(request)) {
|
|
134
|
+
return callback(null, true);
|
|
135
|
+
}
|
|
136
|
+
callback();
|
|
111
137
|
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
performance: {
|
|
141
|
+
chunkSplit: {
|
|
142
|
+
strategy: "all-in-one"
|
|
112
143
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
},
|
|
145
|
+
tools: {
|
|
146
|
+
rspack(config) {
|
|
147
|
+
config.output = config.output || {};
|
|
148
|
+
config.output.asyncChunks = false;
|
|
149
|
+
if (format === "esm") {
|
|
150
|
+
config.output.library = { type: "module" };
|
|
151
|
+
config.output.module = true;
|
|
152
|
+
config.output.chunkFormat = "module";
|
|
153
|
+
config.output.chunkLoading = "import";
|
|
154
|
+
config.output.workerChunkLoading = "import";
|
|
155
|
+
config.experiments = {
|
|
156
|
+
...config.experiments,
|
|
157
|
+
outputModule: true
|
|
158
|
+
};
|
|
159
|
+
config.externalsType = "module-import";
|
|
160
|
+
} else {
|
|
161
|
+
config.output.library = { type: "commonjs-static" };
|
|
162
|
+
}
|
|
163
|
+
config.performance = false;
|
|
164
|
+
config.stats = "errors-warnings";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async function injectEntryStyleReference(entryFile, styleReference) {
|
|
170
|
+
const cssFile = import_path.default.join(import_path.default.dirname(entryFile), "index.css");
|
|
171
|
+
if (!import_fs_extra.default.existsSync(entryFile) || !import_fs_extra.default.existsSync(cssFile)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const content = await import_fs_extra.default.readFile(entryFile, "utf8");
|
|
175
|
+
if (content.startsWith(styleReference)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await import_fs_extra.default.writeFile(entryFile, `${styleReference}
|
|
179
|
+
${content}`);
|
|
120
180
|
}
|
|
121
181
|
function buildLocale(cwd, userConfig, log) {
|
|
122
182
|
log("build client locale");
|
package/lib/buildPlugin.js
CHANGED
|
@@ -53,9 +53,27 @@ var import_getDepsConfig = require("./utils/getDepsConfig");
|
|
|
53
53
|
var import_obfuscationResult = require("./utils/obfuscationResult");
|
|
54
54
|
var import_injectPublicPathPlugin = require("./injectPublicPathPlugin");
|
|
55
55
|
const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
56
|
-
const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
|
|
57
|
-
const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
|
|
56
|
+
const serverGlobalFiles = ["src/**", "!src/client/**", "!src/client-v2/**", ...import_constant.globExcludeFiles];
|
|
58
57
|
const sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/**/__tests__", "!src/**/__benchmarks__"];
|
|
58
|
+
const pluginClientLaneConfig = {
|
|
59
|
+
client: {
|
|
60
|
+
distDir: "client",
|
|
61
|
+
entryDir: "client",
|
|
62
|
+
rootEntryFile: "client.js",
|
|
63
|
+
externalSubpaths: ["client"]
|
|
64
|
+
},
|
|
65
|
+
"client-v2": {
|
|
66
|
+
distDir: "client-v2",
|
|
67
|
+
entryDir: "client-v2",
|
|
68
|
+
rootEntryFile: "client-v2.js",
|
|
69
|
+
externalSubpaths: ["client", "client-v2"]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function getClientGlobalFiles(lane) {
|
|
73
|
+
const entryDir = pluginClientLaneConfig[lane].entryDir;
|
|
74
|
+
const excludedClientDirs = Object.values(pluginClientLaneConfig).map((item) => item.entryDir).filter((dir) => dir !== entryDir).map((dir) => `!src/${dir}/**`);
|
|
75
|
+
return ["src/**", "!src/server/**", ...excludedClientDirs, ...import_constant.globExcludeFiles];
|
|
76
|
+
}
|
|
59
77
|
const external = [
|
|
60
78
|
// nocobase
|
|
61
79
|
"@nocobase/ai",
|
|
@@ -154,7 +172,8 @@ const external = [
|
|
|
154
172
|
"@langchain/anthropic",
|
|
155
173
|
"@langchain/google-genai",
|
|
156
174
|
"@langchain/deepseek",
|
|
157
|
-
"@langchain/ollama"
|
|
175
|
+
"@langchain/ollama",
|
|
176
|
+
"@langchain/mcp-adapters"
|
|
158
177
|
];
|
|
159
178
|
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
|
|
160
179
|
const target_dir = "dist";
|
|
@@ -245,7 +264,19 @@ function deleteServerFiles(cwd, log) {
|
|
|
245
264
|
deep: 1,
|
|
246
265
|
onlyDirectories: true
|
|
247
266
|
});
|
|
248
|
-
|
|
267
|
+
const extraClientDirs = import_fast_glob.default.globSync(["client-v2"], {
|
|
268
|
+
cwd: import_path.default.join(cwd, target_dir),
|
|
269
|
+
absolute: true,
|
|
270
|
+
deep: 1,
|
|
271
|
+
onlyDirectories: true
|
|
272
|
+
});
|
|
273
|
+
[...files, ...dirs.filter((item) => !extraClientDirs.includes(item)), ...extraClientDirs].forEach((item) => {
|
|
274
|
+
if (item.endsWith(`${import_path.default.sep}client-v2`)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (item.endsWith(`${import_path.default.sep}client`)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
249
280
|
import_fs_extra.default.removeSync(item);
|
|
250
281
|
});
|
|
251
282
|
}
|
|
@@ -470,9 +501,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
470
501
|
import_fs_extra.default.removeSync(tsconfig.path);
|
|
471
502
|
await buildServerDeps(cwd, serverFiles, log);
|
|
472
503
|
}
|
|
473
|
-
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
474
|
-
|
|
504
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
|
|
505
|
+
const laneConfig = pluginClientLaneConfig[lane];
|
|
506
|
+
const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
|
|
507
|
+
const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
|
|
508
|
+
if (!import_fs_extra.default.existsSync(rootEntryFile)) {
|
|
509
|
+
log("skip plugin %s build, root entry not found", lane);
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (!import_fs_extra.default.existsSync(entryDir)) {
|
|
513
|
+
log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
|
|
514
|
+
process.exit(-1);
|
|
515
|
+
}
|
|
516
|
+
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
|
|
517
|
+
if (!entry[0]) {
|
|
518
|
+
log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
|
|
519
|
+
process.exit(-1);
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
log("build plugin %s", lane);
|
|
475
523
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
524
|
+
const clientGlobalFiles = getClientGlobalFiles(lane);
|
|
476
525
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
477
526
|
if (isCommercial) {
|
|
478
527
|
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
@@ -485,22 +534,23 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
485
534
|
const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
|
|
486
535
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
487
536
|
(0, import_buildPluginUtils.checkRequire)(clientFiles, log);
|
|
488
|
-
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry:
|
|
489
|
-
const outDir = import_path.default.join(cwd, target_dir,
|
|
537
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
|
|
538
|
+
const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
|
|
490
539
|
const globals = excludePackages.reduce((prev, curr) => {
|
|
491
540
|
if (curr.startsWith("@nocobase")) {
|
|
492
|
-
|
|
541
|
+
laneConfig.externalSubpaths.forEach((subpath) => {
|
|
542
|
+
prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
|
|
543
|
+
});
|
|
493
544
|
}
|
|
494
545
|
prev[curr] = curr;
|
|
495
546
|
return prev;
|
|
496
547
|
}, {});
|
|
497
|
-
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
|
|
498
548
|
const outputFileName = "index.js";
|
|
499
549
|
const compiler = (0, import_core.rspack)({
|
|
500
550
|
mode: "production",
|
|
501
551
|
// mode: "development",
|
|
502
552
|
context: cwd,
|
|
503
|
-
entry:
|
|
553
|
+
entry: `./src/${laneConfig.entryDir}/` + entry[0],
|
|
504
554
|
target: ["web", "es5"],
|
|
505
555
|
output: {
|
|
506
556
|
path: outDir,
|
|
@@ -582,18 +632,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
582
632
|
// *.svg?react
|
|
583
633
|
use: ["@svgr/webpack"]
|
|
584
634
|
},
|
|
585
|
-
{
|
|
586
|
-
test: /\.(?:js|mjs|cjs|ts|tsx)$/,
|
|
587
|
-
exclude: /node_modules/,
|
|
588
|
-
use: {
|
|
589
|
-
loader: "babel-loader",
|
|
590
|
-
options: {
|
|
591
|
-
targets: "defaults",
|
|
592
|
-
// presets: [['@babel/preset-env']],
|
|
593
|
-
plugins: ["react-imported-component/babel"]
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
635
|
{
|
|
598
636
|
test: /\.jsx$/,
|
|
599
637
|
exclude: /[\\/]node_modules[\\/]/,
|
|
@@ -673,7 +711,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
673
711
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
674
712
|
"process.env.NODE_DEBUG": false
|
|
675
713
|
}),
|
|
676
|
-
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name),
|
|
714
|
+
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
|
|
677
715
|
process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
|
|
678
716
|
// plugin options
|
|
679
717
|
// supports: {
|
|
@@ -710,10 +748,12 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
710
748
|
}
|
|
711
749
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
712
750
|
if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
|
|
713
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log, true);
|
|
751
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
|
|
752
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
|
|
714
753
|
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
715
754
|
} else {
|
|
716
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
755
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
|
|
756
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
|
|
717
757
|
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
718
758
|
}
|
|
719
759
|
writeExternalPackageVersion(cwd, log);
|
package/lib/index.d.ts
CHANGED
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import type { RsbuildConfig } from '@rsbuild/core'
|
|
11
11
|
import { Options as TsupConfig } from 'tsup'
|
|
12
|
-
import { InlineConfig as ViteConfig } from 'vite'
|
|
13
12
|
|
|
14
13
|
export type PkgLog = (msg: string, ...args: any[]) => void;
|
|
15
14
|
|
|
16
15
|
interface UserConfig {
|
|
17
16
|
modifyTsupConfig?: (config: TsupConfig) => TsupConfig;
|
|
18
|
-
|
|
17
|
+
modifyRsbuildConfig?: (config: RsbuildConfig) => RsbuildConfig;
|
|
19
18
|
beforeBuild?: (log: PkgLog) => void | Promise<void>;
|
|
20
19
|
afterBuild?: (log: PkgLog) => void | Promise<void>;
|
|
21
20
|
}
|
|
@@ -20,18 +20,30 @@ __export(injectPublicPathPlugin_exports, {
|
|
|
20
20
|
AutoInjectPublicPathPlugin: () => AutoInjectPublicPathPlugin
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(injectPublicPathPlugin_exports);
|
|
23
|
-
function createPluginClientPublicPathDataUri(packageName) {
|
|
23
|
+
function createPluginClientPublicPathDataUri(packageName, clientDistDir) {
|
|
24
24
|
const code = `
|
|
25
|
-
var publicPath = window['
|
|
25
|
+
var publicPath = window['__nocobase_public_path__'] || '';
|
|
26
|
+
if (!publicPath && window.location && window.location.pathname) {
|
|
27
|
+
var marker = '/v2/';
|
|
28
|
+
var pathname = window.location.pathname || '/';
|
|
29
|
+
var index = pathname.indexOf(marker);
|
|
30
|
+
publicPath = index >= 0 ? pathname.slice(0, index + 1) : '/';
|
|
31
|
+
}
|
|
32
|
+
if (publicPath) {
|
|
33
|
+
publicPath = publicPath.replace(/\\/v2\\/?$/, '/');
|
|
34
|
+
}
|
|
35
|
+
if (!publicPath) {
|
|
36
|
+
publicPath = '/';
|
|
37
|
+
}
|
|
26
38
|
if (publicPath.charAt(publicPath.length - 1) !== '/') {
|
|
27
39
|
publicPath += '/';
|
|
28
40
|
}
|
|
29
|
-
__webpack_public_path__ = publicPath + 'static/plugins/${packageName}/dist/
|
|
41
|
+
__webpack_public_path__ = publicPath + 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
30
42
|
`;
|
|
31
43
|
return `data:text/javascript,${encodeURIComponent(code)}`;
|
|
32
44
|
}
|
|
33
|
-
function prependPluginClientPublicPathEntry(entry, packageName) {
|
|
34
|
-
const dataUri = createPluginClientPublicPathDataUri(packageName);
|
|
45
|
+
function prependPluginClientPublicPathEntry(entry, packageName, clientDistDir) {
|
|
46
|
+
const dataUri = createPluginClientPublicPathDataUri(packageName, clientDistDir);
|
|
35
47
|
if (typeof entry === "string") {
|
|
36
48
|
return [dataUri, entry];
|
|
37
49
|
}
|
|
@@ -49,16 +61,24 @@ function prependPluginClientPublicPathEntry(entry, packageName) {
|
|
|
49
61
|
};
|
|
50
62
|
}
|
|
51
63
|
return Object.fromEntries(
|
|
52
|
-
Object.entries(entryConfig).map(([name, value]) => [
|
|
64
|
+
Object.entries(entryConfig).map(([name, value]) => [
|
|
65
|
+
name,
|
|
66
|
+
prependPluginClientPublicPathEntry(value, packageName, clientDistDir)
|
|
67
|
+
])
|
|
53
68
|
);
|
|
54
69
|
}
|
|
55
70
|
class AutoInjectPublicPathPlugin {
|
|
56
|
-
constructor(pluginName) {
|
|
71
|
+
constructor(pluginName, clientDistDir = "client") {
|
|
57
72
|
this.pluginName = pluginName;
|
|
73
|
+
this.clientDistDir = clientDistDir;
|
|
58
74
|
}
|
|
59
75
|
apply(compiler) {
|
|
60
76
|
compiler.hooks.environment.tap("AutoInjectPublicPathPlugin", () => {
|
|
61
|
-
compiler.options.entry = prependPluginClientPublicPathEntry(
|
|
77
|
+
compiler.options.entry = prependPluginClientPublicPathEntry(
|
|
78
|
+
compiler.options.entry,
|
|
79
|
+
this.pluginName,
|
|
80
|
+
this.clientDistDir
|
|
81
|
+
);
|
|
62
82
|
});
|
|
63
83
|
}
|
|
64
84
|
}
|
package/lib/utils/utils.js
CHANGED
|
@@ -86,7 +86,7 @@ function defineConfig(config) {
|
|
|
86
86
|
function getUserConfig(cwd) {
|
|
87
87
|
const config = defineConfig({
|
|
88
88
|
modifyTsupConfig: (config2) => config2,
|
|
89
|
-
|
|
89
|
+
modifyRsbuildConfig: (config2) => config2
|
|
90
90
|
});
|
|
91
91
|
const buildConfigs = import_fast_glob.default.sync(["build.config.js", "build.config.ts"], { cwd });
|
|
92
92
|
if (buildConfigs.length > 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/build",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.12",
|
|
4
4
|
"description": "Library build tool based on rollup.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
"@babel/preset-env": "^7.26.0",
|
|
16
16
|
"@hapi/topo": "^6.0.0",
|
|
17
17
|
"@lerna/project": "4.0.0",
|
|
18
|
+
"@rsbuild/core": "1.7.3",
|
|
18
19
|
"@rsbuild/plugin-babel": "^1.0.3",
|
|
20
|
+
"@rsbuild/plugin-less": "^1.6.2",
|
|
21
|
+
"@rsbuild/plugin-react": "1.4.6",
|
|
22
|
+
"@rsbuild/plugin-svgr": "^1.3.1",
|
|
19
23
|
"@rsdoctor/rspack-plugin": "^0.4.8",
|
|
20
24
|
"@rspack/core": "1.7.8",
|
|
21
25
|
"@svgr/webpack": "^8.1.0",
|
|
@@ -42,8 +46,6 @@
|
|
|
42
46
|
"tsup": "8.2.4",
|
|
43
47
|
"typescript": "5.1.3",
|
|
44
48
|
"update-notifier": "3.0.0",
|
|
45
|
-
"vite-plugin-css-injected-by-js": "^3.2.1",
|
|
46
|
-
"vite-plugin-lib-inject-css": "1.2.0",
|
|
47
49
|
"yargs-parser": "13.1.2"
|
|
48
50
|
},
|
|
49
51
|
"license": "Apache-2.0",
|
|
@@ -51,5 +53,5 @@
|
|
|
51
53
|
"build": "tsup",
|
|
52
54
|
"build:watch": "tsup --watch"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f12c4a75470590b1670ce54510b96ef94c2cd7a2"
|
|
55
57
|
}
|