mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
This commit is contained in:
parent
ca34c64b1d
commit
27e5b1114c
@ -265,7 +265,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
|
||||
}
|
||||
|
||||
// legacy bundle
|
||||
if (legacyPolyfills.size) {
|
||||
if (options.polyfills !== false) {
|
||||
// check if the target needs Promise polyfill because SystemJS relies on it
|
||||
// https://github.com/systemjs/systemjs#ie11-support
|
||||
await detectPolyfills(
|
||||
@ -273,7 +273,9 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
|
||||
targets,
|
||||
legacyPolyfills,
|
||||
)
|
||||
}
|
||||
|
||||
if (legacyPolyfills.size || !options.externalSystemJS) {
|
||||
isDebug &&
|
||||
console.log(
|
||||
`[@vitejs/plugin-legacy] legacy polyfills:`,
|
||||
|
@ -0,0 +1,16 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { isBuild, page, untilUpdated, viteTestUrl } from '~utils'
|
||||
|
||||
test.runIf(isBuild)('includes only a single script tag', async () => {
|
||||
await page.goto(viteTestUrl + '/no-polyfills-no-systemjs.html')
|
||||
|
||||
await untilUpdated(
|
||||
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
|
||||
/.\/assets\/index-legacy-(.+)\.js/,
|
||||
true,
|
||||
)
|
||||
|
||||
expect(await page.locator('script').count()).toBe(1)
|
||||
expect(await page.locator('#vite-legacy-polyfill').count()).toBe(0)
|
||||
expect(await page.locator('#vite-legacy-entry').count()).toBe(1)
|
||||
})
|
@ -0,0 +1,20 @@
|
||||
import { test } from 'vitest'
|
||||
import { isBuild, page, untilUpdated, viteTestUrl } from '~utils'
|
||||
|
||||
test('should load and execute the JS file', async () => {
|
||||
await page.goto(viteTestUrl + '/no-polyfills.html')
|
||||
await untilUpdated(() => page.textContent('main'), '👋', true)
|
||||
})
|
||||
|
||||
test.runIf(isBuild)('includes a script tag for SystemJS', async () => {
|
||||
await untilUpdated(
|
||||
() => page.getAttribute('#vite-legacy-polyfill', 'src'),
|
||||
/.\/assets\/polyfills-legacy-(.+)\.js/,
|
||||
true,
|
||||
)
|
||||
await untilUpdated(
|
||||
() => page.getAttribute('#vite-legacy-entry', 'data-src'),
|
||||
/.\/assets\/index-legacy-(.+)\.js/,
|
||||
true,
|
||||
)
|
||||
})
|
3
playground/legacy/no-polyfills-no-systemjs.html
Normal file
3
playground/legacy/no-polyfills-no-systemjs.html
Normal file
@ -0,0 +1,3 @@
|
||||
<meta charset="UTF-8" />
|
||||
<main></main>
|
||||
<script type="module" src="./no-polyfills-no-systemjs.js"></script>
|
1
playground/legacy/no-polyfills-no-systemjs.js
Normal file
1
playground/legacy/no-polyfills-no-systemjs.js
Normal file
@ -0,0 +1 @@
|
||||
document.querySelector('main').innerHTML = '👋'
|
3
playground/legacy/no-polyfills.html
Normal file
3
playground/legacy/no-polyfills.html
Normal file
@ -0,0 +1,3 @@
|
||||
<meta charset="UTF-8" />
|
||||
<main></main>
|
||||
<script type="module" src="./no-polyfills.js"></script>
|
1
playground/legacy/no-polyfills.js
Normal file
1
playground/legacy/no-polyfills.js
Normal file
@ -0,0 +1 @@
|
||||
document.querySelector('main').innerHTML = '👋'
|
@ -8,6 +8,8 @@
|
||||
"build": "vite build --debug legacy",
|
||||
"build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy",
|
||||
"build:multiple-output": "vite --config ./vite.config-multiple-output.js build",
|
||||
"build:no-polyfills": "vite --config ./vite.config-no-polyfills.js build",
|
||||
"build:no-polyfills-no-systemjs": "vite --config ./vite.config-no-polyfills-no-systemjs.js build",
|
||||
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
|
30
playground/legacy/vite.config-no-polyfills-no-systemjs.js
Normal file
30
playground/legacy/vite.config-no-polyfills-no-systemjs.js
Normal file
@ -0,0 +1,30 @@
|
||||
import path from 'node:path'
|
||||
import legacy from '@vitejs/plugin-legacy'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [
|
||||
legacy({
|
||||
renderModernChunks: false,
|
||||
polyfills: false,
|
||||
externalSystemJS: true,
|
||||
}),
|
||||
{
|
||||
name: 'remove crossorigin attribute',
|
||||
transformIndexHtml: (html) => html.replaceAll('crossorigin', ''),
|
||||
enforce: 'post',
|
||||
},
|
||||
],
|
||||
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
index: path.resolve(__dirname, 'no-polyfills-no-systemjs.html'),
|
||||
},
|
||||
},
|
||||
},
|
||||
testConfig: {
|
||||
baseRoute: '/no-polyfills-no-systemjs/',
|
||||
},
|
||||
})
|
29
playground/legacy/vite.config-no-polyfills.js
Normal file
29
playground/legacy/vite.config-no-polyfills.js
Normal file
@ -0,0 +1,29 @@
|
||||
import path from 'node:path'
|
||||
import legacy from '@vitejs/plugin-legacy'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [
|
||||
legacy({
|
||||
renderModernChunks: false,
|
||||
polyfills: false,
|
||||
}),
|
||||
{
|
||||
name: 'remove crossorigin attribute',
|
||||
transformIndexHtml: (html) => html.replaceAll('crossorigin', ''),
|
||||
enforce: 'post',
|
||||
},
|
||||
],
|
||||
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
index: path.resolve(__dirname, 'no-polyfills.html'),
|
||||
},
|
||||
},
|
||||
},
|
||||
testConfig: {
|
||||
baseRoute: '/no-polyfills/',
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user