diff --git a/packages/playground/legacy/__tests__/legacy.spec.ts b/packages/playground/legacy/__tests__/legacy.spec.ts index b8025694437502..65bd39ff32b1d1 100644 --- a/packages/playground/legacy/__tests__/legacy.spec.ts +++ b/packages/playground/legacy/__tests__/legacy.spec.ts @@ -83,4 +83,8 @@ if (isBuild) { test('should emit css file', async () => { expect(listAssets().some((filename) => filename.endsWith('.css'))) }) + + test('includes structuredClone polyfill which is supported after core-js v3', () => { + expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"') + }) } diff --git a/packages/playground/legacy/index.html b/packages/playground/legacy/index.html index bdc2feac6b4fbe..d481766463cd4f 100644 --- a/packages/playground/legacy/index.html +++ b/packages/playground/legacy/index.html @@ -1,6 +1,7 @@

+
diff --git a/packages/playground/legacy/main.js b/packages/playground/legacy/main.js index b05acf439bdff8..31579b4717810d 100644 --- a/packages/playground/legacy/main.js +++ b/packages/playground/legacy/main.js @@ -21,6 +21,12 @@ text('#env', `is legacy: ${isLegacy}`) // Iterators text('#iterators', [...new Set(['hello'])].join('')) +// structuredClone is supported core.js v3.20.0+ +text( + '#features-after-corejs-3', + JSON.stringify(structuredClone({ foo: 'foo' })) +) + // babel-helpers // Using `String.raw` to inject `@babel/plugin-transform-template-literals` // helpers. diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index 626b48f85ea955..41f7157ebfc533 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -330,7 +330,10 @@ function viteLegacyPlugin(options = {}) { loose: false, useBuiltIns: needPolyfills ? 'usage' : false, corejs: needPolyfills - ? { version: 3, proposals: false } + ? { + version: require('core-js/package.json').version, + proposals: false + } : undefined, shippedProposals: true, ignoreBrowserslistConfig: options.ignoreBrowserslistConfig