@vitejs/plugin-legacy 2.0.0-beta.0 → 2.0.0-beta.1

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/dist/index.cjs CHANGED
@@ -21,15 +21,40 @@ async function loadBabel() {
21
21
  }
22
22
  return babel;
23
23
  }
24
- function getBaseInHTML(urlRelativePath, baseOptions, config) {
25
- return baseOptions.url ?? (baseOptions.relative ? path__default.posix.join(path__default.posix.relative(urlRelativePath, "").slice(0, -2), "./") : config.base);
24
+ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRelative) {
25
+ const { renderBuiltUrl } = config.experimental;
26
+ let relative = config.base === "" || config.base === "./";
27
+ if (renderBuiltUrl) {
28
+ const result = renderBuiltUrl(filename, {
29
+ hostId,
30
+ hostType,
31
+ type,
32
+ ssr: !!config.build.ssr
33
+ });
34
+ if (typeof result === "object") {
35
+ if (result.runtime) {
36
+ throw new Error(`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`);
37
+ }
38
+ if (typeof result.relative === "boolean") {
39
+ relative = result.relative;
40
+ }
41
+ } else if (result) {
42
+ return result;
43
+ }
44
+ }
45
+ if (relative && !config.build.ssr) {
46
+ return toRelative(filename, hostId);
47
+ } else {
48
+ return config.base + filename;
49
+ }
26
50
  }
27
- function getAssetsBase(urlRelativePath, config) {
28
- return getBaseInHTML(urlRelativePath, config.experimental.buildAdvancedBaseOptions.assets, config);
51
+ function getBaseInHTML(urlRelativePath, config) {
52
+ return config.base === "./" || config.base === "" ? path__default.posix.join(path__default.posix.relative(urlRelativePath, "").slice(0, -2), "./") : config.base;
29
53
  }
30
54
  function toAssetPathFromHtml(filename, htmlPath, config) {
31
55
  const relativeUrlPath = vite.normalizePath(path__default.relative(config.root, htmlPath));
32
- return getAssetsBase(relativeUrlPath, config) + filename;
56
+ const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
57
+ return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
33
58
  }
34
59
  const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`;
35
60
  const legacyPolyfillId = "vite-legacy-polyfill";
package/dist/index.mjs CHANGED
@@ -12,15 +12,40 @@ async function loadBabel() {
12
12
  }
13
13
  return babel;
14
14
  }
15
- function getBaseInHTML(urlRelativePath, baseOptions, config) {
16
- return baseOptions.url ?? (baseOptions.relative ? path.posix.join(path.posix.relative(urlRelativePath, "").slice(0, -2), "./") : config.base);
15
+ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRelative) {
16
+ const { renderBuiltUrl } = config.experimental;
17
+ let relative = config.base === "" || config.base === "./";
18
+ if (renderBuiltUrl) {
19
+ const result = renderBuiltUrl(filename, {
20
+ hostId,
21
+ hostType,
22
+ type,
23
+ ssr: !!config.build.ssr
24
+ });
25
+ if (typeof result === "object") {
26
+ if (result.runtime) {
27
+ throw new Error(`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`);
28
+ }
29
+ if (typeof result.relative === "boolean") {
30
+ relative = result.relative;
31
+ }
32
+ } else if (result) {
33
+ return result;
34
+ }
35
+ }
36
+ if (relative && !config.build.ssr) {
37
+ return toRelative(filename, hostId);
38
+ } else {
39
+ return config.base + filename;
40
+ }
17
41
  }
18
- function getAssetsBase(urlRelativePath, config) {
19
- return getBaseInHTML(urlRelativePath, config.experimental.buildAdvancedBaseOptions.assets, config);
42
+ function getBaseInHTML(urlRelativePath, config) {
43
+ return config.base === "./" || config.base === "" ? path.posix.join(path.posix.relative(urlRelativePath, "").slice(0, -2), "./") : config.base;
20
44
  }
21
45
  function toAssetPathFromHtml(filename, htmlPath, config) {
22
46
  const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
23
- return getAssetsBase(relativeUrlPath, config) + filename;
47
+ const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
48
+ return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
24
49
  }
25
50
  const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`;
26
51
  const legacyPolyfillId = "vite-legacy-polyfill";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "scripts": {
20
20
  "dev": "unbuild --stub",
21
21
  "build": "unbuild && pnpm run patch-cjs",
22
- "patch-cjs": "esno ../../scripts/patchCJS.ts",
22
+ "patch-cjs": "tsx ../../scripts/patchCJS.ts",
23
23
  "prepublishOnly": "npm run build"
24
24
  },
25
25
  "engines": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
37
37
  "dependencies": {
38
- "@babel/standalone": "^7.18.5",
38
+ "@babel/standalone": "^7.18.7",
39
39
  "core-js": "^3.23.1",
40
40
  "magic-string": "^0.26.2",
41
41
  "regenerator-runtime": "^0.13.9",
@@ -46,7 +46,7 @@
46
46
  "vite": "^3.0.0-alpha"
47
47
  },
48
48
  "devDependencies": {
49
- "@babel/core": "^7.18.5",
49
+ "@babel/core": "^7.18.6",
50
50
  "vite": "workspace:*"
51
51
  }
52
52
  }