Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-dynamic-import

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-dynamic-import - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

6

dist/index.js

@@ -37,3 +37,3 @@ "use strict";

return;
if (await ((_b = options.filter) === null || _b === void 0 ? void 0 : _b.call(options, code, id, opts)) === false)
if (((_b = options.filter) === null || _b === void 0 ? void 0 : _b.call(options, pureId)) === false)
return;

@@ -51,3 +51,3 @@ const ast = this.parse(code);

return;
// the user explicitly avoids this import
// the user explicitly ignore this import
if ((_a = options.viteIgnore) === null || _a === void 0 ? void 0 : _a.call(options, importeeRaw, pureId)) {

@@ -175,3 +175,3 @@ dynamicImportRecords.push({

files = files.map(file => !file.startsWith('.') ? /* 🚧-③ */ './' + file : file);
onFiles && (files = (await onFiles(files, pureId)) || files);
onFiles && (files = onFiles(files, pureId) || files);
let aliasWithFiles;

@@ -178,0 +178,0 @@ if (alias) {

import type { AcornNode as AcornNode2 } from 'rollup';
import type { Plugin } from 'vite';
export declare type AcornNode<T = any> = AcornNode2 & Record<string, T>;
export interface DynamicImportOptions {
filter?: (...args: Parameters<Plugin['transform']>) => false | void | Promise<false | void>;
filter?: (id: string) => false | void;
/**

@@ -15,7 +14,8 @@ * This option will change `./*` to `./** /*`

*/
onFiles?: (files: string[], id: string) => typeof files | void | Promise<typeof files | void>;
onFiles?: (files: string[], id: string) => typeof files | void;
/**
* It will add `@vite-ignore`
* `import(/*@vite-ignore* / 'import-path')`
*/
viteIgnore?: (rawImportee: string, id: string) => true | Promise<true | void> | void;
viteIgnore?: (rawImportee: string, id: string) => true | void;
}
{
"name": "vite-plugin-dynamic-import",
"version": "0.9.0",
"version": "0.9.1",
"description": "Enhance Vite builtin dynamic import",

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

@@ -13,3 +13,3 @@ # vite-plugin-dynamic-import

- Try to fix the wizard import path
- Compatible with `@rollup/plugin-dynamic-import-vars` restrictions
- Compatible `@rollup/plugin-dynamic-import-vars` restrictions

@@ -33,3 +33,3 @@ ## Install

**See more cases 👉 [playground/vite-plugin-dynamic-import](https://github.com/caoxiemeihao/vite-plugins/tree/main/playground/vite-plugin-dynamic-import)**
**Cases 👉 [vite-plugin-dynamic-import/src/main.ts](https://github.com/caoxiemeihao/vite-plugins/blob/main/playground/vite-plugin-dynamic-import/src/main.ts)**

@@ -44,3 +44,3 @@ ## API

export interface DynamicImportOptions {
filter?: (...args: Parameters<Plugin['transform']>) => false | void | Promise<false | void>
filter?: (id: string) => false | void
/**

@@ -51,7 +51,15 @@ * This option will change `./*` to `./** /*`

depth?: boolean
/**
* If you want to exclude some files
* e.g `type.d.ts`, `interface.ts`
*/
onFiles?: (files: string[], id: string) => typeof files | void
/**
* It will add `@vite-ignore`
* `import(/*@vite-ignore* / 'import-path')`
*/
viteIgnore?: (rawImportee: string, id: string) => true | void
}
```
See the `filter` args [vite/src/node/plugin.ts#L131](https://github.com/vitejs/vite/blob/9a7b133d45979de0604b9507d87a2ffa2187a387/packages/vite/src/node/plugin.ts#L131)
## How and why?

@@ -58,0 +66,0 @@

@@ -12,3 +12,4 @@ # vite-plugin-dynamic-import

- 支持在 `import()` 中使用别名
- 基于 `glob` 使得限制更加宽松
- 尝试修复诡异的 import 路径
- 兼容 `@rollup/plugin-dynamic-import-vars` 限制

@@ -32,3 +33,3 @@ ## 安装

**更复杂的使用场景 👉 [playground/vite-plugin-dynamic-import](https://github.com/caoxiemeihao/vite-plugins/tree/main/playground/vite-plugin-dynamic-import)**
**案例 👉 [vite-plugin-dynamic-import/src/main.ts](https://github.com/caoxiemeihao/vite-plugins/blob/main/playground/vite-plugin-dynamic-import/src/main.ts)**

@@ -44,3 +45,3 @@

export interface DynamicImportOptions {
filter?: (...args: Parameters<Plugin['transform']>) => false | void | Promise<false | void>
filter?: (id: string) => false | void
/**

@@ -51,7 +52,15 @@ * 这个选项将会把 `./*` 变成 `./** /*`

depth?: boolean
/**
* 如果你想排除一些文件
* 举俩🌰 `type.d.ts`, `interface.ts`
*/
onFiles?: (files: string[], id: string) => typeof files | void
/**
* 将会在 import 中添加 `@vite-ignore`
* `import(/*@vite-ignore* / 'import-path')`
*/
viteIgnore?: (rawImportee: string, id: string) => true | void
}
```
`filter` 入参详情看这里 [vite/src/node/plugin.ts#L131](https://github.com/vitejs/vite/blob/9a7b133d45979de0604b9507d87a2ffa2187a387/packages/vite/src/node/plugin.ts#L131)
## 作此为甚?

@@ -63,4 +72,4 @@

├── src
| ├── views
| | ├── foo
| └── views
| | ├ foo
| | | └── index.js

@@ -70,3 +79,2 @@ | | └── bar.js

└── vite.config.js
```

@@ -73,0 +81,0 @@

@@ -51,3 +51,3 @@ import path from 'path'

if (!hasDynamicImport(code)) return
if (await options.filter?.(code, id, opts) === false) return
if (options.filter?.(pureId) === false) return

@@ -66,3 +66,3 @@ const ast = this.parse(code)

// the user explicitly avoids this import
// the user explicitly ignore this import
if (options.viteIgnore?.(importeeRaw, pureId)) {

@@ -252,3 +252,3 @@ dynamicImportRecords.push({

files = files.map(file => !file.startsWith('.') ? /* 🚧-③ */'./' + file : file)
onFiles && (files = (await onFiles(files, pureId)) || files)
onFiles && (files = onFiles(files, pureId) || files)

@@ -255,0 +255,0 @@ let aliasWithFiles: GlobHasFiles['alias']

@@ -7,3 +7,3 @@ import type { AcornNode as AcornNode2 } from 'rollup'

export interface DynamicImportOptions {
filter?: (...args: Parameters<Plugin['transform']>) => false | void | Promise<false | void>
filter?: (id: string) => false | void
/**

@@ -18,8 +18,8 @@ * This option will change `./*` to `./** /*`

*/
onFiles?: (files: string[], id: string) => typeof files | void | Promise<typeof files | void>
onFiles?: (files: string[], id: string) => typeof files | void
/**
* It will add `@vite-ignore`
* `import(/*@vite-ignore* / 'import-path')`
*/
// import(/*@vite-ignore*/ 'import-path')
viteIgnore?: (rawImportee: string, id: string) => true | Promise<true | void> | void
viteIgnore?: (rawImportee: string, id: string) => true | void
}
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