@vitejs/plugin-legacy
Advanced tools
Comparing version 1.4.4 to 1.5.0
@@ -0,1 +1,11 @@ | ||
# [1.5.0](https://github.com/vitejs/vite/compare/plugin-legacy@1.4.4...plugin-legacy@1.5.0) (2021-07-27) | ||
### Bug Fixes | ||
* **deps:** update all non-major dependencies ([#4387](https://github.com/vitejs/vite/issues/4387)) ([2f900ba](https://github.com/vitejs/vite/commit/2f900ba4d4ad8061e0046898e8d1de3129e7f784)) | ||
* **plugin-legacy:** legacy fallback for dynamic import ([#3885](https://github.com/vitejs/vite/issues/3885)) ([fc6d8f1](https://github.com/vitejs/vite/commit/fc6d8f1d3efe836f17f3c45375dd3749128b8137)) | ||
## [1.4.4](https://github.com/vitejs/vite/compare/plugin-legacy@1.4.3...plugin-legacy@1.4.4) (2021-07-12) | ||
@@ -2,0 +12,0 @@ |
61
index.js
@@ -18,5 +18,9 @@ // @ts-check | ||
const legacyPolyfillId = 'vite-legacy-polyfill' | ||
const legacyEntryId = 'vite-legacy-entry' | ||
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))` | ||
const dynamicFallbackInlineCode = `!function(){try{new Function("m","return import(m)")}catch(o){console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}}();` | ||
const blankDynamicImport = `import('data:text/javascript;base64,Cg==');` | ||
const legacyEnvVarMarker = `__VITE_IS_LEGACY__` | ||
@@ -35,2 +39,3 @@ | ||
const genLegacy = options.renderLegacyChunks !== false | ||
const genDynamicFallback = genLegacy | ||
@@ -81,5 +86,2 @@ const debugFlag = process.env.DEBUG | ||
} | ||
if (genLegacy) { | ||
config.build.polyfillDynamicImport = true | ||
} | ||
} | ||
@@ -129,3 +131,3 @@ } | ||
// legacy bundle | ||
if (legacyPolyfills.size) { | ||
if (legacyPolyfills.size || genDynamicFallback) { | ||
if (!legacyPolyfills.has('es.promise')) { | ||
@@ -235,24 +237,27 @@ // check if the target needs Promise polyfill because SystemJS relies | ||
const ms = new MagicString(raw) | ||
if (genDynamicFallback && chunk.isEntry) { | ||
ms.prepend(blankDynamicImport) | ||
} | ||
if (raw.includes(legacyEnvVarMarker)) { | ||
const re = new RegExp(legacyEnvVarMarker, 'g') | ||
if (config.build.sourcemap) { | ||
const s = new MagicString(raw) | ||
let match | ||
while ((match = re.exec(raw))) { | ||
s.overwrite( | ||
match.index, | ||
match.index + legacyEnvVarMarker.length, | ||
`false` | ||
) | ||
} | ||
return { | ||
code: s.toString(), | ||
map: s.generateMap({ hires: true }) | ||
} | ||
} else { | ||
return raw.replace(re, `false`) | ||
let match | ||
while ((match = re.exec(raw))) { | ||
ms.overwrite( | ||
match.index, | ||
match.index + legacyEnvVarMarker.length, | ||
`false` | ||
) | ||
} | ||
} | ||
return null | ||
if (config.build.sourcemap) { | ||
return { | ||
code: ms.toString(), | ||
map: ms.generateMap({ hires: true }) | ||
} | ||
} | ||
return ms.toString() | ||
} | ||
@@ -366,2 +371,3 @@ | ||
nomodule: true, | ||
id: legacyPolyfillId, | ||
src: `${config.base}${legacyPolyfillFilename}` | ||
@@ -401,2 +407,12 @@ }, | ||
// 5. inject dynamic import fallback entry | ||
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) { | ||
tags.push({ | ||
tag: 'script', | ||
attrs: { type: 'module' }, | ||
children: dynamicFallbackInlineCode, | ||
injectTo: 'head' | ||
}) | ||
} | ||
return { | ||
@@ -649,3 +665,4 @@ html, | ||
createHash('sha256').update(safari10NoModuleFix).digest('base64'), | ||
createHash('sha256').update(systemJSInlineCode).digest('base64') | ||
createHash('sha256').update(systemJSInlineCode).digest('base64'), | ||
createHash('sha256').update(dynamicFallbackInlineCode).digest('base64') | ||
] |
{ | ||
"name": "@vitejs/plugin-legacy", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"license": "MIT", | ||
@@ -29,6 +29,6 @@ "author": "Evan You", | ||
"dependencies": { | ||
"@babel/standalone": "^7.14.7", | ||
"@babel/standalone": "^7.14.8", | ||
"core-js": "^3.15.2", | ||
"magic-string": "^0.25.7", | ||
"regenerator-runtime": "^0.13.7", | ||
"regenerator-runtime": "^0.13.9", | ||
"systemjs": "^6.10.2" | ||
@@ -35,0 +35,0 @@ }, |
@@ -125,2 +125,9 @@ # @vitejs/plugin-legacy [![npm](https://img.shields.io/npm/v/@vitejs/plugin-legacy.svg)](https://npmjs.com/package/@vitejs/plugin-legacy) | ||
## Dynamic Import | ||
The legacy plugin offers a way to use native `import()` in the modern build while falling back to the legacy build in browsers with native ESM but without dynamic import support (e.g. Legacy Edge). This feature works by injecting a runtime check and loading the legacy bundle with SystemJs runtime if needed. There are the following drawbacks: | ||
- Modern bundle is downloaded in all ESM browsers | ||
- Modern bundle throws `SyntaxError` in browsers without dynamic import | ||
## Polyfill Specifiers | ||
@@ -151,8 +158,9 @@ | ||
The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc) and SystemJS initialization. If you have a strict CSP policy requirement, you will need to [add the corresponding hashes to your `script-src` list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script): | ||
The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc), SystemJS initialization, and dynamic import fallback. If you have a strict CSP policy requirement, you will need to [add the corresponding hashes to your `script-src` list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script): | ||
- `MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=` | ||
- `tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=` | ||
- `T9h4ixy0FtNsCwAyTfBtIY6uV5ZhMeNQIlL42GAKEME=` | ||
These values can also be retrived via | ||
These values can also be retrieved via | ||
@@ -159,0 +167,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35375
621
174
Updated@babel/standalone@^7.14.8
Updatedregenerator-runtime@^0.13.9