@vnejs/build 0.2.1 → 0.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/build",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Build tools for @vnejs",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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,9 +10,10 @@ 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
19
  const isClientOutput = (asset) =>
@@ -75,9 +76,7 @@ module.exports = (rootPath, options = {}) => {
75
76
  transformIndexHtml: {
76
77
  order: "pre",
77
78
  handler(html) {
78
- if (html.includes(entryScript)) return html;
79
-
80
- return html.replace("</body>", ` <script type="module" src="${entryScript}"></script>\n </body>`);
79
+ return injectDeferredEntry(html, entryScript);
81
80
  },
82
81
  },
83
82
  },
@@ -99,6 +98,9 @@ module.exports = (rootPath, options = {}) => {
99
98
  emptyOutDir: false,
100
99
  minify: !isDev,
101
100
  watch: options.watch ? {} : null,
101
+ modulePreload: {
102
+ resolveDependencies: (_filename, deps, { hostType }) => (hostType === "html" ? [] : deps),
103
+ },
102
104
  assetsInlineLimit: (filePath) => (/\.(jpe?g|png|gif|svg)$/i.test(filePath) ? Number.POSITIVE_INFINITY : 4096),
103
105
  rolldownOptions: {
104
106
  input: htmlFile,