
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
vite-plugin-add-importmap
Advanced tools
当在开发模式下使用npm包,在生产模式下想要使用CDN,又不需要更改任何代码 使用该插件即可轻松实现
前提:添加CDN的包需要有支持浏览器的ESM标准
yarn add vite-plugin-add-importmap -D
# or
npm i vite-plugin-add-importmap -D
# or
pnpm install vite-plugin-add-importmap -D
Options:
importmap:CND的映射表isAdd:是否添加importmap,默认会添加;若不会添加,则置为falseConfiguration plugin in vite.config.ts
import { defineConfig } from 'vite'
import AddImportmap from 'vite-plugin-add-importmap'
export default defineConfig({
plugins: [
// other plugins
AddImportmap({
importMap: {
vue: 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.31/vue.esm-browser.min.js'
},
isAdd: true // 是否是生产环境,可选
})
],
build: {
build: {
rollupOptions: {
external: ['vue'] // 将对应的包排除在bundle外部
}
}
})
Run
pnpm install
pnpm run build
打开dist/index.html可看到添加了importmap
// 查看最终效果
pnpm preview
FAQs
A vite plugin adding importmap to HTML file
We found that vite-plugin-add-importmap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.