npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-resolve

v2.5.2

Published

Custom resolve module content.

Downloads

20,788

Readme

vite-plugin-resolve

Custom resolve module content

NPM version NPM Downloads awesome-vite

English | 简体中文

  • 🤔 You can think of this as the implementation of the official tutorial 👉 Virtual Modules Convention
  • 🌱 What you see is what you get
  • 📦 Out of the box (builtin Vue, React, Antd, Element and others)
  • 🚀 Browser, Node.js, Electron

Install

npm i vite-plugin-resolve -D

Usage

You can load any code snippets you want (ESM format)

import resolve from 'vite-plugin-resolve'

export default {
  plugins: [
    resolve({
      // Browser
      vue: `
        const vue = window.Vue;
        const version = vue.version;
        export {
          vue as default,
          version,
        }
      `,
      // Node.js, Electron
      electron: `
        const { ipcRenderer, shell } = require('electron');
        export {
          ipcRenderer,
          shell,
        }
      `,
    }),
  ]
}

// Use in your app
import Vue, { version } from 'vue'
import { ipcRenderer, shell } from 'electron'

// Make sure that index.html has introduced the CDN file.
// e.g.
// <script src="https://unpkg.com/[email protected]/dist/vue.global.js"></script>

Use with lib-esm

npm i lib-esm
import resolve from 'vite-plugin-resolve'
import libEsm from 'lib-esm'

export default {
  plugins: [
    resolve({
      // Let's use lodash as an example
      lodash: () => {
        const snippets = libEsm({
          // lodash iife name
          window: '_',
          // export memebers
          exports: [
            'chunk',
            'curry',
            'debounce',
            'throttle',
          ],
        })
        return `${snippets.window}\n${snippets.exports}`
      },
    }),
  ],
}

// Use in your app
import _, { chunk, curry, debounce, throttle } from 'lodash'

Use in Electron 👉 electron-vite-vue

Builtin modules

This like Vite external plugin

import resolve from 'vite-plugin-resolve'
import {
  ant_design_vue,
  antd,
  axios,
  element_plus,
  element_ui,
  pinia,
  react_dom,
  react_router_dom,
  react_router,
  react,
  redux,
  vue_composition_api,
  vue_demi,
  vue_router,
  vue,
  vuex,
} from 'vite-plugin-resolve/presets'

export default {
  plugins: [
    resolve({
      // e.g.
      // external-lib: lib-name.version
      vue: vue.v3,
      react: react.v18,
    }),
  ]
}

// Use in your app
import Vue, { ref, reactive, computed, watch } from 'vue'
import React, { useState, useEffect } from 'react'

API (Define)

resolve(entries)

function resolve(entries: {
  [moduleId: string]:
  | import('rollup').LoadResult
  | import('vite').Plugin['load'];
}): import('vite').Plugin[];

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