@vnejs/build 0.0.39 → 0.0.42
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 +1 -1
- package/src/cli.js +1 -0
- package/src/client/utils.js +24 -5
- package/src/client/vite.config.js +11 -9
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ program
|
|
|
24
24
|
program
|
|
25
25
|
//
|
|
26
26
|
.command("client")
|
|
27
|
+
.option("-m, --mode <mode>", "build mode (development | production)")
|
|
27
28
|
.option("-w, --watch", "watch mode", false)
|
|
28
29
|
.option("-q, --quiet", "no console mode", false)
|
|
29
30
|
.action(async (options) => require("./client")(getRootDir())(options));
|
package/src/client/utils.js
CHANGED
|
@@ -3,6 +3,22 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
const entryDir = "entry";
|
|
5
5
|
|
|
6
|
+
const resolveIndexedFile = (dir) => {
|
|
7
|
+
const candidates = ["index.ts", "index.js"].map((name) => path.join(dir, name));
|
|
8
|
+
|
|
9
|
+
return candidates.find((file) => fs.existsSync(file));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const resolveEntryFile = (entryRoot) => {
|
|
13
|
+
const entryFile = resolveIndexedFile(entryRoot);
|
|
14
|
+
|
|
15
|
+
if (!entryFile) {
|
|
16
|
+
throw new Error(`entry file not found: expected ${["index.ts", "index.js"].map((name) => path.join(entryRoot, name)).join(" or ")}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return entryFile;
|
|
20
|
+
};
|
|
21
|
+
|
|
6
22
|
const getVnejsScopedPackageNames = (rootPath, scopePrefix) => {
|
|
7
23
|
let dir = rootPath;
|
|
8
24
|
|
|
@@ -63,20 +79,22 @@ const getGameModScripts = (rootPath) => {
|
|
|
63
79
|
|
|
64
80
|
return fs
|
|
65
81
|
.readdirSync(gamePath)
|
|
66
|
-
.
|
|
67
|
-
.
|
|
82
|
+
.map((modDir) => resolveIndexedFile(path.join(gamePath, modDir, "scripts")))
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
.sort((modScriptA, modScriptB) => {
|
|
85
|
+
const modA = path.basename(path.dirname(path.dirname(modScriptA)));
|
|
86
|
+
const modB = path.basename(path.dirname(path.dirname(modScriptB)));
|
|
68
87
|
const orderDiff = getModOrder(modB, gamePath) - getModOrder(modA, gamePath);
|
|
69
88
|
|
|
70
89
|
return orderDiff !== 0 ? orderDiff : modA.localeCompare(modB);
|
|
71
|
-
})
|
|
72
|
-
.map((modDir) => path.join(gamePath, modDir, "scripts", "index.js"));
|
|
90
|
+
});
|
|
73
91
|
};
|
|
74
92
|
|
|
75
93
|
const importStatementPattern = /^[ \t]*import\s[\s\S]*?;[ \t]*(?:\n|$)/gm;
|
|
76
94
|
|
|
77
95
|
const toImportStatements = (targets) => targets.map((target) => `import ${JSON.stringify(target)};`);
|
|
78
96
|
|
|
79
|
-
// Порядок side-effect импортов важен: uis → bundle → entry/index.js → game/*/scripts → тело модуля.
|
|
97
|
+
// Порядок side-effect импортов важен: uis → bundle → entry/index.(ts|js) → game/*/scripts/index.(ts|js) → тело модуля.
|
|
80
98
|
const orderEntryImports = (code, { leadingImports = [], trailingImports = [] } = {}) => {
|
|
81
99
|
const leading = toImportStatements(leadingImports);
|
|
82
100
|
const trailing = toImportStatements(trailingImports);
|
|
@@ -106,6 +124,7 @@ const cleanClientOutput = (distPath, isClientOutput) => {
|
|
|
106
124
|
|
|
107
125
|
module.exports = {
|
|
108
126
|
entryDir,
|
|
127
|
+
resolveEntryFile,
|
|
109
128
|
getVnejsScopedPackageNames,
|
|
110
129
|
getGameModIndexJsonFiles,
|
|
111
130
|
getGameModScripts,
|
|
@@ -4,6 +4,7 @@ const react = require("@vitejs/plugin-react").default;
|
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
entryDir,
|
|
7
|
+
resolveEntryFile,
|
|
7
8
|
getVnejsScopedPackageNames,
|
|
8
9
|
getGameModIndexJsonFiles,
|
|
9
10
|
getGameModScripts,
|
|
@@ -21,17 +22,18 @@ const isBundleModule = (id) => /(@vnejs[/\\]bundles\.|[/\\]bundles[/\\])/.test(i
|
|
|
21
22
|
|
|
22
23
|
const isUisModule = (id) => /(@vnejs[/\\]uis\.|[/\\]uis[/\\])/.test(id);
|
|
23
24
|
|
|
25
|
+
const resolveMode = (options) =>
|
|
26
|
+
options.mode ?? (process.env.NODE_ENV === "development" ? "development" : "production");
|
|
27
|
+
|
|
24
28
|
module.exports = (rootPath, options = {}) => {
|
|
25
|
-
const
|
|
29
|
+
const mode = resolveMode(options);
|
|
30
|
+
const isDev = mode === "development";
|
|
26
31
|
const entryRoot = path.join(rootPath, entryDir);
|
|
27
32
|
const distPath = path.join(rootPath, "dist");
|
|
28
|
-
const entryFile =
|
|
33
|
+
const entryFile = resolveEntryFile(entryRoot);
|
|
34
|
+
const entryScript = `./${path.basename(entryFile)}`;
|
|
29
35
|
const htmlFile = path.join(entryRoot, "index.html");
|
|
30
36
|
|
|
31
|
-
if (!fs.existsSync(entryFile)) {
|
|
32
|
-
throw new Error(`entry file not found: ${entryFile}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
37
|
if (!fs.existsSync(htmlFile)) {
|
|
36
38
|
throw new Error(`html template not found: ${htmlFile}`);
|
|
37
39
|
}
|
|
@@ -49,7 +51,7 @@ module.exports = (rootPath, options = {}) => {
|
|
|
49
51
|
configFile: false,
|
|
50
52
|
root: entryRoot,
|
|
51
53
|
base: "./",
|
|
52
|
-
mode
|
|
54
|
+
mode,
|
|
53
55
|
publicDir: false,
|
|
54
56
|
logLevel: options.quiet ? "warn" : "info",
|
|
55
57
|
define: {
|
|
@@ -73,9 +75,9 @@ module.exports = (rootPath, options = {}) => {
|
|
|
73
75
|
transformIndexHtml: {
|
|
74
76
|
order: "pre",
|
|
75
77
|
handler(html) {
|
|
76
|
-
if (html.includes(
|
|
78
|
+
if (html.includes(entryScript)) return html;
|
|
77
79
|
|
|
78
|
-
return html.replace("</body>",
|
|
80
|
+
return html.replace("</body>", ` <script type="module" src="${entryScript}"></script>\n </body>`);
|
|
79
81
|
},
|
|
80
82
|
},
|
|
81
83
|
},
|