@marko/vite 4.1.12 → 4.1.14

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.
Files changed (2) hide show
  1. package/dist/index.mjs +21 -17
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ import path5 from "path";
4
4
  import crypto from "crypto";
5
5
  import anyMatch from "anymatch";
6
6
  import { pathToFileURL } from "url";
7
- import { transform as cjsToEsm } from "@chialab/cjs-to-esm";
8
7
 
9
8
  // src/server-entry-template.ts
10
9
  import path from "path";
@@ -54,22 +53,16 @@ function renderAssets(slot) {
54
53
  // To avoid FOUC we will hide the page until all of these modules are loaded.
55
54
  const { preload } = entry;
56
55
  if (preload) {
57
- let sep = "";
58
- html += \`<script\${this.___viteInjectAttrs}>((root=document.documentElement)=>{\`;
59
- html += "root.style.visibility='hidden';";
60
- html += "document.currentScript.remove();";
61
- html += "Promise.allSettled([";
62
-
56
+ html += \`<script class=marko-vite-preload blocking=render type=module\${this.___viteInjectAttrs}>\`;
63
57
  for (const id of preload) {
64
- html += \`\${sep}import(\${JSON.stringify(base + id)})\`;
65
- sep = ",";
58
+ html += \`import \${JSON.stringify(base + id)};\`;
66
59
  }
67
60
 
68
- html += "]).then(()=>{";
69
- html += "root.style.visibility='';";
61
+ html += "document.querySelectorAll('.marko-vite-preload').forEach((el) => el.remove());";
62
+ html += "document.documentElement.style.visibility='';";
70
63
  html +=
71
- "if(root.getAttribute('style')==='')root.removeAttribute('style')";
72
- html += "})})()</script>";
64
+ "if(document.documentElement.getAttribute('style')==='')document.documentElement.removeAttribute('style');";
65
+ html += "</script><script class=marko-vite-preload>document.documentElement.style.visibility='hidden'</script>";
73
66
  }
74
67
  }`}
75
68
 
@@ -664,6 +657,7 @@ var babelCaller = {
664
657
  supportsExportNamespaceFrom: true
665
658
  };
666
659
  var registeredTagLib = false;
660
+ var cjsToEsm;
667
661
  function markoPlugin(opts = {}) {
668
662
  let compiler;
669
663
  let { linked = true } = opts;
@@ -1088,10 +1082,20 @@ function markoPlugin(opts = {}) {
1088
1082
  if (!isBuild) {
1089
1083
  const ext = path5.extname(id);
1090
1084
  if (ext === ".cjs" || ext === ".js" && isCJSModule(id)) {
1091
- try {
1092
- return await cjsToEsm(source);
1093
- } catch {
1094
- return null;
1085
+ if (cjsToEsm === void 0) {
1086
+ try {
1087
+ cjsToEsm = (await import("@chialab/cjs-to-esm")).transform;
1088
+ } catch {
1089
+ cjsToEsm = null;
1090
+ return null;
1091
+ }
1092
+ }
1093
+ if (cjsToEsm) {
1094
+ try {
1095
+ return await cjsToEsm(source);
1096
+ } catch {
1097
+ return null;
1098
+ }
1095
1099
  }
1096
1100
  }
1097
1101
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "4.1.12",
4
+ "version": "4.1.14",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {