@vnejs/build 0.2.2 → 0.2.4
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/client/utils.js +20 -0
- package/src/client/vite.config.js +8 -8
- package/src/data/utils.js +8 -12
package/package.json
CHANGED
package/src/client/utils.js
CHANGED
|
@@ -124,6 +124,24 @@ const cleanClientOutput = (distPath, isClientOutput) => {
|
|
|
124
124
|
});
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
+
const createDeferredEntryScript = (entryScript) => ` <script type="module">
|
|
128
|
+
const afterFirstPaint = (fn) => requestAnimationFrame(() => requestAnimationFrame(fn));
|
|
129
|
+
const boot = () => import(${JSON.stringify(entryScript)});
|
|
130
|
+
|
|
131
|
+
if (document.readyState === "loading") {
|
|
132
|
+
document.addEventListener("DOMContentLoaded", () => afterFirstPaint(boot), { once: true });
|
|
133
|
+
} else {
|
|
134
|
+
afterFirstPaint(boot);
|
|
135
|
+
}
|
|
136
|
+
</script>
|
|
137
|
+
`;
|
|
138
|
+
|
|
139
|
+
const injectDeferredEntry = (html, entryScript) => {
|
|
140
|
+
if (html.includes(entryScript)) return html;
|
|
141
|
+
|
|
142
|
+
return html.replace("</body>", `${createDeferredEntryScript(entryScript)} </body>`);
|
|
143
|
+
};
|
|
144
|
+
|
|
127
145
|
module.exports = {
|
|
128
146
|
entryDir,
|
|
129
147
|
resolveEntryFile,
|
|
@@ -132,4 +150,6 @@ module.exports = {
|
|
|
132
150
|
getGameModScripts,
|
|
133
151
|
orderEntryImports,
|
|
134
152
|
cleanClientOutput,
|
|
153
|
+
createDeferredEntryScript,
|
|
154
|
+
injectDeferredEntry,
|
|
135
155
|
};
|
|
@@ -10,20 +10,19 @@ const {
|
|
|
10
10
|
getGameModScripts,
|
|
11
11
|
orderEntryImports,
|
|
12
12
|
cleanClientOutput,
|
|
13
|
+
injectDeferredEntry,
|
|
13
14
|
} = require("./utils");
|
|
14
15
|
|
|
15
|
-
const buildChunkPattern = /^(index|uis|bundle|web)\.[a-zA-Z0-9_-]+\.js$/;
|
|
16
|
+
const buildChunkPattern = /^(index|entry|uis|bundle|web)\.[a-zA-Z0-9_-]+\.js$/;
|
|
16
17
|
const legacyChunkPattern = /^vendors\.[a-zA-Z0-9_.-]+$/;
|
|
17
18
|
|
|
18
|
-
const isClientOutput = (asset) =>
|
|
19
|
-
asset === "index.html" || buildChunkPattern.test(asset) || legacyChunkPattern.test(asset) || asset.startsWith("assets/");
|
|
19
|
+
const isClientOutput = (asset) => asset === "index.html" || buildChunkPattern.test(asset) || legacyChunkPattern.test(asset) || asset.startsWith("assets/");
|
|
20
20
|
|
|
21
21
|
const isBundleModule = (id) => /(@vnejs[/\\]bundles\.|[/\\]bundles[/\\])/.test(id);
|
|
22
22
|
|
|
23
23
|
const isUisModule = (id) => /(@vnejs[/\\]uis\.|[/\\]uis[/\\])/.test(id);
|
|
24
24
|
|
|
25
|
-
const resolveMode = (options) =>
|
|
26
|
-
options.mode ?? (process.env.NODE_ENV === "development" ? "development" : "production");
|
|
25
|
+
const resolveMode = (options) => options.mode ?? (process.env.NODE_ENV === "development" ? "development" : "production");
|
|
27
26
|
|
|
28
27
|
module.exports = (rootPath, options = {}) => {
|
|
29
28
|
const mode = resolveMode(options);
|
|
@@ -75,9 +74,7 @@ module.exports = (rootPath, options = {}) => {
|
|
|
75
74
|
transformIndexHtml: {
|
|
76
75
|
order: "pre",
|
|
77
76
|
handler(html) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return html.replace("</body>", ` <script type="module" src="${entryScript}"></script>\n </body>`);
|
|
77
|
+
return injectDeferredEntry(html, entryScript);
|
|
81
78
|
},
|
|
82
79
|
},
|
|
83
80
|
},
|
|
@@ -99,6 +96,9 @@ module.exports = (rootPath, options = {}) => {
|
|
|
99
96
|
emptyOutDir: false,
|
|
100
97
|
minify: !isDev,
|
|
101
98
|
watch: options.watch ? {} : null,
|
|
99
|
+
modulePreload: {
|
|
100
|
+
resolveDependencies: (_filename, deps, { hostType }) => (hostType === "html" ? [] : deps),
|
|
101
|
+
},
|
|
102
102
|
assetsInlineLimit: (filePath) => (/\.(jpe?g|png|gif|svg)$/i.test(filePath) ? Number.POSITIVE_INFINITY : 4096),
|
|
103
103
|
rolldownOptions: {
|
|
104
104
|
input: htmlFile,
|
package/src/data/utils.js
CHANGED
|
@@ -60,10 +60,13 @@ const parseLines = (lines, label) => {
|
|
|
60
60
|
|
|
61
61
|
curKeys = curKeys.filter(({ indent } = {}) => indent < line.length - line.trim().length);
|
|
62
62
|
|
|
63
|
-
const args = curKeys.reduce(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const args = curKeys.reduce(
|
|
64
|
+
(acc, { key }) => {
|
|
65
|
+
if (!acc[key]) acc[key] = {};
|
|
66
|
+
return acc[key];
|
|
67
|
+
},
|
|
68
|
+
realLines[realLines.length - 1].args,
|
|
69
|
+
);
|
|
67
70
|
|
|
68
71
|
args[key] = mapValue(value);
|
|
69
72
|
} else {
|
|
@@ -169,14 +172,7 @@ const mergePlainObjects = (target, source) => {
|
|
|
169
172
|
for (const [key, value] of Object.entries(source)) {
|
|
170
173
|
const current = result[key];
|
|
171
174
|
|
|
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
|
-
) {
|
|
175
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && current !== null && typeof current === "object" && !Array.isArray(current)) {
|
|
180
176
|
result[key] = mergePlainObjects(current, value);
|
|
181
177
|
continue;
|
|
182
178
|
}
|