Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vite-plugin-resolve

Custom resolve module content

NPM version NPM Downloads awesome-vite

English | 简体中文

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

Install

npm i vite-plugin-resolve -D

Usage

You can load any code snippet you want

import resolve from 'vite-plugin-resolve'

export default {
  plugins: [
    resolve({
      vue: `const vue = window.Vue; export { vue as default }`,
    }),
  ]
}

In you App

import Vue from 'vue'

This like Vite external plugin
You you can see more about external 👉 vite-plugin-fast-external

Load a file

Support nested module id, support return Promise

import fs from 'fs'

resolve({
  'path/filename': () => fs.promise.readFile('path', 'utf-8'),
})

Electron

Resolve Electron Renderer-process

resolve({
  electron: `
    const electron = require("electron");
    export { electron as default }
    const export shell = electron.shell;
    const export ipcRenderer = electron.ipcRenderer;
    // ...others
  `,
})

In you App(Renderer-process)

import { shell, ipcRenderer } from 'electron'

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

  1. Bypass the builtin vite:resolve plugin
  2. Reasonably avoid Pre-Bundling

Keywords

FAQs

Package last updated on 24 Apr 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc