@vnejs/build 0.0.36 → 0.0.38
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/package.json +3 -7
- package/src/client/index.js +6 -1
- package/src/client/utils.js +3 -9
- package/src/client/vite.config.js +10 -17
- package/src/data/index.js +2 -4
- package/src/data/utils.js +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "Build tools for @vnejs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,12 +16,8 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@vitejs/plugin-react": "^5.1.2",
|
|
19
|
+
"@vitejs/plugin-react": "~6.0.2",
|
|
21
20
|
"commander": "13.1.0",
|
|
22
|
-
"
|
|
23
|
-
"react": "~19.2.7",
|
|
24
|
-
"react-dom": "~19.2.7",
|
|
25
|
-
"vite": "^7.0.4"
|
|
21
|
+
"vite": "~8.0.16"
|
|
26
22
|
}
|
|
27
23
|
}
|
package/src/client/index.js
CHANGED
|
@@ -15,7 +15,12 @@ module.exports = (rootDir) => async (options) => {
|
|
|
15
15
|
process.on("SIGTERM", closeWatcher);
|
|
16
16
|
}
|
|
17
17
|
} catch (error) {
|
|
18
|
-
|
|
18
|
+
if (error.errors) {
|
|
19
|
+
error.errors.forEach((buildError) => console.error(buildError));
|
|
20
|
+
} else {
|
|
21
|
+
console.error(error);
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
process.exit(1);
|
|
20
25
|
}
|
|
21
26
|
};
|
package/src/client/utils.js
CHANGED
|
@@ -72,15 +72,13 @@ const getGameModScripts = (rootPath) => {
|
|
|
72
72
|
.map((modDir) => path.join(gamePath, modDir, "scripts", "index.js"));
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
const resolvePackageDir = (name, rootPath) => path.dirname(require.resolve(`${name}/package.json`, { paths: [rootPath] }));
|
|
76
|
-
|
|
77
75
|
const importStatementPattern = /^[ \t]*import\s[\s\S]*?;[ \t]*(?:\n|$)/gm;
|
|
78
76
|
|
|
79
77
|
const toImportStatements = (targets) => targets.map((target) => `import ${JSON.stringify(target)};`);
|
|
80
78
|
|
|
81
|
-
// Порядок side-effect импортов важен:
|
|
82
|
-
const orderEntryImports = (code, {
|
|
83
|
-
const leading = toImportStatements(
|
|
79
|
+
// Порядок side-effect импортов важен: uis → bundle → entry/index.js → game/*/scripts → тело модуля.
|
|
80
|
+
const orderEntryImports = (code, { leadingImports = [], trailingImports = [] } = {}) => {
|
|
81
|
+
const leading = toImportStatements(leadingImports);
|
|
84
82
|
const trailing = toImportStatements(trailingImports);
|
|
85
83
|
const matches = [...code.matchAll(importStatementPattern)];
|
|
86
84
|
|
|
@@ -106,15 +104,11 @@ const cleanClientOutput = (distPath, isClientOutput) => {
|
|
|
106
104
|
});
|
|
107
105
|
};
|
|
108
106
|
|
|
109
|
-
const vendorImports = ["react", "react-dom", "@bem-react/classname"];
|
|
110
|
-
|
|
111
107
|
module.exports = {
|
|
112
108
|
entryDir,
|
|
113
|
-
vendorImports,
|
|
114
109
|
getVnejsScopedPackageNames,
|
|
115
110
|
getGameModIndexJsonFiles,
|
|
116
111
|
getGameModScripts,
|
|
117
|
-
resolvePackageDir,
|
|
118
112
|
orderEntryImports,
|
|
119
113
|
cleanClientOutput,
|
|
120
114
|
};
|
|
@@ -4,21 +4,18 @@ const react = require("@vitejs/plugin-react").default;
|
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
entryDir,
|
|
7
|
-
vendorImports,
|
|
8
7
|
getVnejsScopedPackageNames,
|
|
9
8
|
getGameModIndexJsonFiles,
|
|
10
9
|
getGameModScripts,
|
|
11
|
-
resolvePackageDir,
|
|
12
10
|
orderEntryImports,
|
|
13
11
|
cleanClientOutput,
|
|
14
12
|
} = require("./utils");
|
|
15
13
|
|
|
16
|
-
const buildChunkPattern = /^(index|
|
|
14
|
+
const buildChunkPattern = /^(index|uis|bundle|web)\.[a-zA-Z0-9_-]+\.js$/;
|
|
15
|
+
const legacyChunkPattern = /^vendors\.[a-zA-Z0-9_.-]+$/;
|
|
17
16
|
|
|
18
|
-
const isClientOutput = (asset) =>
|
|
19
|
-
|
|
20
|
-
const isVendorModule = (id) =>
|
|
21
|
-
/[/\\](react|react-dom)([/\\]|$)/.test(id) || id.includes("@bem-react/classname");
|
|
17
|
+
const isClientOutput = (asset) =>
|
|
18
|
+
asset === "index.html" || buildChunkPattern.test(asset) || legacyChunkPattern.test(asset) || asset.startsWith("assets/");
|
|
22
19
|
|
|
23
20
|
const isBundleModule = (id) => /(@vnejs[/\\]bundles\.|[/\\]bundles[/\\])/.test(id);
|
|
24
21
|
|
|
@@ -44,7 +41,6 @@ module.exports = (rootPath, options = {}) => {
|
|
|
44
41
|
|
|
45
42
|
const buildOrderedEntry = (code) =>
|
|
46
43
|
orderEntryImports(code, {
|
|
47
|
-
vendorImports,
|
|
48
44
|
leadingImports: [...uisPackages, ...bundlePackages],
|
|
49
45
|
trailingImports: getGameModScripts(rootPath),
|
|
50
46
|
});
|
|
@@ -60,10 +56,6 @@ module.exports = (rootPath, options = {}) => {
|
|
|
60
56
|
"process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production"),
|
|
61
57
|
},
|
|
62
58
|
resolve: {
|
|
63
|
-
alias: {
|
|
64
|
-
react: resolvePackageDir("react", rootPath),
|
|
65
|
-
"react-dom": resolvePackageDir("react-dom", rootPath),
|
|
66
|
-
},
|
|
67
59
|
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
|
|
68
60
|
},
|
|
69
61
|
plugins: [
|
|
@@ -106,7 +98,7 @@ module.exports = (rootPath, options = {}) => {
|
|
|
106
98
|
minify: !isDev,
|
|
107
99
|
watch: options.watch ? {} : null,
|
|
108
100
|
assetsInlineLimit: (filePath) => (/\.(jpe?g|png|gif|svg)$/i.test(filePath) ? Number.POSITIVE_INFINITY : 4096),
|
|
109
|
-
|
|
101
|
+
rolldownOptions: {
|
|
110
102
|
input: htmlFile,
|
|
111
103
|
output: {
|
|
112
104
|
entryFileNames: "[name].[hash].js",
|
|
@@ -118,10 +110,11 @@ module.exports = (rootPath, options = {}) => {
|
|
|
118
110
|
|
|
119
111
|
return "assets/[name].[hash][extname]";
|
|
120
112
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
codeSplitting: {
|
|
114
|
+
groups: [
|
|
115
|
+
{ name: "uis", test: isUisModule, priority: 20 },
|
|
116
|
+
{ name: "bundle", test: isBundleModule, priority: 10 },
|
|
117
|
+
],
|
|
125
118
|
},
|
|
126
119
|
},
|
|
127
120
|
},
|
package/src/data/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const { runBuildData, buildModsJson } = require("./utils");
|
|
3
|
+
const { runBuildData, buildModsJson, mergePlainObjects } = require("./utils");
|
|
6
4
|
|
|
7
5
|
const buildDataFunc = (gameDir, distDir) => {
|
|
8
6
|
let result = {};
|
|
@@ -10,7 +8,7 @@ const buildDataFunc = (gameDir, distDir) => {
|
|
|
10
8
|
fs.readdirSync(gameDir).forEach((modDir) => {
|
|
11
9
|
const newData = runBuildData({ modDir: path.join(gameDir, modDir) });
|
|
12
10
|
|
|
13
|
-
result =
|
|
11
|
+
result = mergePlainObjects(result, newData);
|
|
14
12
|
|
|
15
13
|
newData.data.media && fs.writeFileSync(path.join(distDir, `media.${modDir}.json`), JSON.stringify(newData.data.media));
|
|
16
14
|
});
|
package/src/data/utils.js
CHANGED
|
@@ -163,6 +163,30 @@ const readModIndexJson = (modPath) => {
|
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
+
const mergePlainObjects = (target, source) => {
|
|
167
|
+
const result = { ...target };
|
|
168
|
+
|
|
169
|
+
for (const [key, value] of Object.entries(source)) {
|
|
170
|
+
const current = result[key];
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
value !== null &&
|
|
174
|
+
typeof value === "object" &&
|
|
175
|
+
!Array.isArray(value) &&
|
|
176
|
+
current !== null &&
|
|
177
|
+
typeof current === "object" &&
|
|
178
|
+
!Array.isArray(current)
|
|
179
|
+
) {
|
|
180
|
+
result[key] = mergePlainObjects(current, value);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
result[key] = value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return result;
|
|
188
|
+
};
|
|
189
|
+
|
|
166
190
|
const buildModsJson = (gameDir) =>
|
|
167
191
|
fs.readdirSync(gameDir).reduce((mods, modDir) => {
|
|
168
192
|
const modPath = path.join(gameDir, modDir);
|
|
@@ -178,4 +202,4 @@ const buildModsJson = (gameDir) =>
|
|
|
178
202
|
return mods;
|
|
179
203
|
}, {});
|
|
180
204
|
|
|
181
|
-
module.exports = { runBuildData, buildModsJson };
|
|
205
|
+
module.exports = { runBuildData, buildModsJson, mergePlainObjects };
|