@teages/nuxt-legacy
一個用於支援舊版瀏覽器的 Nuxt 模組。
設定
透過一個命令將模組安裝到您的 Nuxt 應用中
# vite
pnpm add @teages/nuxt-legacy @vitejs/plugin-legacy
然後在你的 nuxt.config.ts
中配置它
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
'@teages/nuxt-legacy'
],
legacy: {
vite: {}, // `@vitejs/plugin-legacy` options
},
})
最大相容性(不推薦)
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
'@teages/nuxt-legacy'
],
legacy: {
vite: {
targets: ['fully supports proxy'],
modernPolyfills: true,
},
},
})
相容性
Nuxt & @vitejs/plugin-legacy
該模組相容 Nuxt ^3.18.0 || >=4.0.3
和 @vitejs/plugin-legacy ^7.0.0
此版本。
由於該模組不依賴任何隱式行為,因此它應該適用於任何更高版本的 Nuxt。但我會在 Nuxt 釋出次要或主要版本後重新檢查相容性。
檢查當前模組版本的結果
Nuxt 版本 | @vitejs/plugin-legacy | Chrome 49 | Chrome 61 | Chrome 91 |
---|---|---|---|---|
3.18.0 | 7.0.0 | ✅ 透過 | ✅ 透過 | ✅ 透過 |
4.0.3 | 7.0.0 | ✅ 透過 | ✅ 透過 | ✅ 透過 |
瀏覽器支援
該模組已在以下瀏覽器中進行測試
- Chrome 49:Vue 3 的最低要求版本
- Chrome 61:支援 ESM 但不支援廣泛可用的功能
- Chrome 91:不支援
Object.hasOwn
但可以透過 polyfill 填充 - 最新版 Chrome
你可以透過使用你的目標瀏覽器訪問遊樂場進行自我測試。
內容安全策略
它注入了一些內聯指令碼以修復舊版瀏覽器相容性。雜湊值與最新版本的 @vitejs/plugin-legacy
保持同步,當前值為
sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=
sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=
sha256-ZxAi3a7m9Mzbc+Z1LGuCCK5Xee6reDkEPRas66H9KSo=
sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=
cspHashes
也可在模組中使用
import { cspHashes } from '@teages/nuxt-legacy'
鳴謝
- IlyaSemenov/nuxt-vite-legacy:@IlyaSemenov 的模組,帶有他的想法
- BrowserStack。此專案透過 BrowserStack 進行測試。
貢獻
本地開發
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release