vite 支援optional Chaining(可選鏈判斷運算子 ?.)和 nullishCoalescingOperator (空值合併運算子 ??)
安裝 babel 可選鏈判斷運算子,空值合併運算子 相容依賴
yarn add @babel/plugin-proposal-optional-chaining --dev
yarn add @babel/plugin-proposal-nullish-coalescing-operator -dev
vite.config.ts
新增配置
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import checker from "vite-plugin-checker";
import vitePluginImp from "vite-plugin-imp";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
plugins: [
react({
babel: {
plugins: [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
],
},
}),
],
};
});
vue 請使用 @vitejs/plugin-vue
[未測試]