Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-legacy): polyfill latest features #7514

Merged
merged 1 commit into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/playground/legacy/__tests__/legacy.spec.ts
Expand Up @@ -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"')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hacky...
Please tell me if there is a better way.

})
}
1 change: 1 addition & 0 deletions packages/playground/legacy/index.html
@@ -1,6 +1,7 @@
<h1 id="app"></h1>
<div id="env"></div>
<div id="iterators"></div>
<div id="features-after-corejs-3"></div>
<div id="babel-helpers"></div>
<div id="assets"></div>
<script type="module" src="./main.js"></script>
6 changes: 6 additions & 0 deletions packages/playground/legacy/main.js
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-legacy/index.js
Expand Up @@ -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
Expand Down