vite-plugin-resolve
Advanced tools
Comparing version 1.4.4 to 1.5.0
import { Plugin, UserConfig } from 'vite'; | ||
export interface Resolves { | ||
[moduleId: string]: string | (() => string | Promise<string>); | ||
[moduleId: string]: string | ((args: { dir: string }) => string | Promise<string | void> | void) | void; | ||
} | ||
@@ -47,3 +47,3 @@ | ||
export interface GenerateESModule { | ||
(cacheDir: string, resolves: Resolves): Promise<void>; | ||
(dir: string, resolves: Resolves): Promise<void>; | ||
} | ||
@@ -50,0 +50,0 @@ |
15
index.js
@@ -10,3 +10,3 @@ const fs = require('fs'); | ||
let root = process.cwd(); | ||
let cacheDir = '.vite-plugin-resolve'; | ||
let dir = '.vite-plugin-resolve'; | ||
@@ -23,3 +23,3 @@ return { | ||
// absolute path | ||
cacheDir = path.join(node_modules(root), cacheDir); | ||
dir = path.join(node_modules(root), dir); | ||
@@ -30,6 +30,6 @@ if (optimizeDepsExclude) modifyOptimizeDepsExclude(config, Object.keys(resolves)); | ||
config, | ||
Object.keys(resolves).map(moduleId => ({ [moduleId]: path.join(cacheDir, moduleId) })), | ||
Object.keys(resolves).map(moduleId => ({ [moduleId]: path.join(dir, moduleId) })), | ||
); | ||
await generateESModule(cacheDir, resolves); | ||
await generateESModule(dir, resolves); | ||
}, | ||
@@ -42,7 +42,8 @@ } | ||
*/ | ||
async function generateESModule(cacheDir, resolves) { | ||
async function generateESModule(dir, resolves) { | ||
// generate custom-resolve module file | ||
for (const [module, strOrFn] of Object.entries(resolves)) { | ||
const moduleId = path.join(cacheDir, module + '.js'); | ||
const moduleContent = await (typeof strOrFn === 'function' ? strOrFn() : strOrFn); | ||
const moduleId = path.join(dir, module + '.js'); | ||
const moduleContent = await (typeof strOrFn === 'function' ? strOrFn({ dir }) : strOrFn); | ||
if (moduleContent == null) continue; | ||
@@ -49,0 +50,0 @@ // supported nest moduleId ('@scope/name') |
{ | ||
"name": "vite-plugin-resolve", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"description": "Custom resolve module content.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -48,3 +48,3 @@ # vite-plugin-resolve | ||
export type viteResolve = ( | ||
resolves: [moduleId: string]: string | (() => string | Promise<string>), | ||
resolves: [moduleId: string]: string | ((args: { dir: string }) => string | Promise<string | void> | void) | void, | ||
options?: { | ||
@@ -51,0 +51,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9740
140