🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

vite-plugin-add-importmap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-add-importmap

A vite plugin adding importmap to HTML file

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

一个添加importmap的vite插件

当在开发模式下使用npm包,在生产模式下想要使用CDN,又不需要更改任何代码 使用该插件即可轻松实现

前提:添加CDN的包需要有支持浏览器的ESM标准

Installation (yarn or npm)

yarn add vite-plugin-add-importmap -D
# or
npm i vite-plugin-add-importmap -D
# or
pnpm install vite-plugin-add-importmap -D

Usage

Options:

  • importmap:CND的映射表
  • isAdd:是否添加importmap,默认会添加;若不会添加,则置为false

Configuration 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外部
    }
  }
})

Example

Run

pnpm install

pnpm run build

打开dist/index.html可看到添加了importmap

// 查看最终效果
pnpm preview

Keywords

vite

FAQs

Package last updated on 02 Jun 2023

Did you know?

Socket

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.

Install

Related posts