vite: Unable to support functions such as "optional chain" in QQ browser 10 or chrome 70
Describe the bug
Invalid Babel configuration
// App.vue
const num = window?.num ?? 9;
console.log(num);
// babel.config.js
module.exports = {
presets: [
"@vue/cli-plugin-babel/preset",
"@babel/plugin-proposal-optional-chaining"
]
};
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import babel from 'vite-babel-plugin'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
(babel as any)(),
// legacy({
// additionalLegacyPolyfills: ['@babel/plugin-proposal-optional-chaining'],
// targets: ['chrome 70']
// })
],
build: {
target: ['es2015'],
// target: ['chrome70']
},
})
Reproduction
https://github.com/yangdan8/vite2-vue3-ts-demo
System Info
QQ browser 10
Chrome70
Used Package Manager
yarn
Logs
Uncaught SyntaxError: Unexpected token .
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 21 (5 by maintainers)
Commits related to this issue
- fix: Add "target" to support chrome 70 (#5222) — committed to yangdan8/vite by deleted user 3 years ago
- fix(#5222): Add "target" to support chrome 70 — committed to yangdan8/vite by deleted user 3 years ago
- fix(#5222): Add "target" to support chrome 70 — committed to yangdan8/vite by deleted user 3 years ago
@vitejs/plugin-react
或者@vitejs/plugin-vue
应该支持传入babel配置,实测react可用