Socket
Socket
Sign inDemoInstall

vite-plugin-resolve

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-resolve - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

2

index.d.ts

@@ -14,2 +14,2 @@ import { Plugin } from 'vite';

export const lib2esm: import('./presets').Lib2esm;
export const lib2esm: import('./presets').Lib2esm;

@@ -46,2 +46,2 @@ /**

module.exports.lib2esm = require('./presets').lib2esm;
module.exports.lib2esm = require('./presets').lib2esm;
{
"name": "vite-plugin-resolve",
"version": "2.1.1",
"version": "2.1.2",
"description": "Custom resolve module content.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,3 +6,2 @@ export interface LibMeta {

export interface Lib2esmOptions {

@@ -12,3 +11,3 @@ /**

*
* e.g.
* 🌰 e.g.
* ```js

@@ -21,9 +20,7 @@ * const _M_ = require('lib') // cjs

*/
format?: 'cjs' | 'iife',
format?: "cjs" | "iife",
}
export interface Lib2esm {
(name: string): string
(name: string, options: Lib2esmOptions): string
(name: string, members: string[]): string
(name: string, members: string[], options: Lib2esmOptions): string
(name: string, options?: Lib2esmOptions): string
(name: string, members: string[], options?: Lib2esmOptions): string
}

@@ -93,2 +90,2 @@ export declare const lib2esm: Lib2esm

v4: string
}
}

@@ -26,3 +26,3 @@ const antd_vue_v1 = require('./ant-design-vue-v1');

*/
exports.lib2esm = function (name, ...args) {
exports.lib2esm = function (name, ...args) {
if (!args.length) {

@@ -29,0 +29,0 @@ return exports.lib2esm(name, [], {});

@@ -62,2 +62,3 @@ # vite-plugin-resolve

import resolve, { lib2esm } from 'vite-plugin-resolve'
export default {

@@ -83,3 +84,3 @@ plugins: [

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

@@ -124,4 +125,4 @@

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

@@ -150,3 +151,3 @@

*
* e.g.
* 🌰 e.g.
* ```js

@@ -159,9 +160,7 @@ * const _M_ = require('lib') // cjs

*/
format?: 'cjs' | 'iife',
format?: "cjs" | "iife",
}
export interface Lib2esm {
(name: string): string
(name: string, options: Lib2esmOptions): string
(name: string, members: string[]): string
(name: string, members: string[], options: Lib2esmOptions): string
(name: string, options?: Lib2esmOptions): string
(name: string, members: string[], options?: Lib2esmOptions): string
}

@@ -168,0 +167,0 @@ export declare const lib2esm: Lib2esm

@@ -12,3 +12,3 @@ # vite-plugin-resolve

🤔 你可以认为它是官方教程的一个实现 👉 [Virtual Modules Convention](https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention)
📦 **开箱即用**, 内置 Vue, React, Antd, Element 等等
📦 **开箱即用**, 内置 Vue, React, Antd, Element 等等
🌱 支持自定义 external 代码段

@@ -25,3 +25,3 @@ ✅ Browser, Node.js, Electron

你可以加载任何你想要的代码段
你可以加载任何你想要的代码段 **(ESM 格式)**

@@ -37,4 +37,7 @@ ```ts

const vue = window.Vue;
export { vue as default }
export const version = vue.version;
const version = vue.version;
export {
vue as default,
version,
}
`,

@@ -48,3 +51,2 @@ // Node.js, Electron

}
// ...others
`,

@@ -54,7 +56,4 @@ }),

}
```
你的逻辑代码
```ts
// 你的逻辑代码
import Vue, { version } from 'vue'

@@ -64,31 +63,32 @@ import { ipcRenderer, shell } from 'electron'

**加载文件**
你可以很容易地使用' lib2esm() '来定制一些内容
支持嵌套模块命名,支持返回 Promise
```js
import resolve, { lib2esm } from 'vite-plugin-resolve'
```ts
import fs from 'fs'
resolve({
'path/filename': () => fs.promise.readFile('path', 'utf-8'),
})
```
## API
#### resolve(entries)
**entries**
```ts
{
[moduleId: string]:
| ReturnType<Plugin['load']>
| ((...args: Parameters<Plugin['load']>) => ReturnType<Plugin['load']>)
export default {
plugins: [
resolve({
// 用 lodash 举个 🌰
lodash: lib2esm(
// lodash 全局名称
'_',
// export memebers
[
'chunk',
'curry',
'debounce',
'throttle',
],
),
}),
]
}
// 使用
import _, { chunk, curry, debounce, throttle } from 'lodash'
```
详细的返回值类型看这里 [rollup/types.d.ts#L272](https://github.com/rollup/rollup/blob/b8315e03f9790d610a413316fbf6d565f9340cab/src/rollup/types.d.ts#L272)
** 在 Electron 中使用 ** 👉 [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue/blob/main/packages/renderer/vite.config.ts)
## 使用内置模块
## 内置模块

@@ -115,43 +115,60 @@ 这个场景就是 Vite external plugin

} from 'vite-plugin-resolve/presets'
export default {
plugins: [
resolve({
// e.g.
// external-lib: lib-name.version
vue: vue.v3,
react: react.v18,
}),
]
}
// 使用
import { h, ref, reactive, watch } from 'vue'
import Vue, { ref, reactive, computed, watch } from 'vue'
import React, { useState, useEffect } from 'react'
```
**Advance**, you can use `lib2esm()` to customize some things
## API
```js
import resolve from 'vite-plugin-resolve'
import { lib2esm } from 'vite-plugin-resolve/presets'
export default {
plugins: [
resolve({
// 用 lodash 举个 🌰
lodash: lib2esm(
// lodash 全局名称
'_',
// export memebers
[
'chunk',
'curry',
'debounce',
'throttle',
],
),
}),
]
`resolve(entries)`
```ts
type entries = {
[moduleId: string]:
| ReturnType<Plugin['load']>
| ((...args: Parameters<Plugin['load']>) => ReturnType<Plugin['load']>)
}
// 使用
import { chunk, curry, debounce, throttle } from 'lodash'
import _, { chunk, curry, debounce, throttle } from 'lodash'
```
**在 Electron 中使用** 👉 [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue/blob/main/packages/renderer/vite.config.ts)
*你可以在此处看到返回值类型定义 [rollup/types.d.ts#L272](https://github.com/rollup/rollup/blob/b8315e03f9790d610a413316fbf6d565f9340cab/src/rollup/types.d.ts#L272)*
`lib2esm(name[,members[,options]])`
```ts
export interface Lib2esmOptions {
/**
* 生成代码段格式
*
* 🌰 e.g.
* ```js
* const _M_ = require('lib') // cjs
* const _M_ = window['lib'] // iife
* ```
*
* @default "iife"
*/
format?: "cjs" | "iife",
}
export interface Lib2esm {
(name: string, options?: Lib2esmOptions): string
(name: string, members: string[], options?: Lib2esmOptions): string
}
export declare const lib2esm: Lib2esm
```
## 这与官方的 Demo 有何异同?

@@ -158,0 +175,0 @@

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