🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

vite-plugin-resolve

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-resolve

Custom resolve module content.

2.0.0
Source
npm
Version published
Weekly downloads
4.1K
-11.3%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-resolve NPM version awesome-vite

Custom resolve module content

English | 简体中文

  • Compatible Browser, Node.js and Electron
  • You can think of this as the implementation of the official tutorial 👉 Virtual Modules Convention

Install

npm i vite-plugin-resolve -D

Usage

import { defineConfig } from 'vite'
import resolve from 'vite-plugin-resolve'

export default defineConfig({
  plugins: [
    resolve({
      // Resolve custom module content
      // This like Vite external plugin
      vue: `const vue = window.Vue; export { vue as default }`,
    }),
  ]
})

Load a local file

resolve({
  // Support nested module id
  // Support return Promise
  '@scope/name': () => require('fs').promises.readFile('path', 'utf-8'),
})

Electron

resolve({
  // Resolve Electron ipcRenderer in Renderer-process
  electron: `const { ipcRenderer } = require('electron'); export { ipcRenderer };`,
})

API

resolve(entries)

entries

{
  [moduleId: string]:
    | ReturnType<Plugin['load']>
    | ((...args: Parameters<Plugin['load']>) => ReturnType<Plugin['load']>)
}

You can see the return value type definition here rollup/types.d.ts#L272

What's different from the official Demo?

There are two main differences

  • Bypass the builtin vite:resolve plugin
  • Reasonably avoid Pre-Bundling treatment

Keywords

vite

FAQs

Package last updated on 19 Mar 2022

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