vite-plugin-wasm-pack
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -11,2 +11,4 @@ "use strict"; | ||
function vitePluginWasmPack(crates) { | ||
const prefix = '@vite-plugin-wasm-pack@'; | ||
const pkg = 'pkg'; | ||
const cratePaths = narrowing_1.isString(crates) ? [crates] : crates; | ||
@@ -19,3 +21,3 @@ function wasmFilename(cratePath) { | ||
const wasmFile = wasmFilename(cratePath); | ||
wasmMap.set(wasmFile, path_1.default.join(cratePath, 'pkg', wasmFile)); | ||
wasmMap.set(wasmFile, path_1.default.join(cratePath, pkg, wasmFile)); | ||
}); | ||
@@ -25,5 +27,22 @@ return { | ||
enforce: 'pre', | ||
resolveId(id) { | ||
for (let i = 0; i < cratePaths.length; i++) { | ||
if (path_1.default.basename(cratePaths[i]) === id) | ||
return prefix + id; | ||
} | ||
return null; | ||
}, | ||
async load(id) { | ||
if (id.indexOf(prefix) === 0) { | ||
id = id.replace(prefix, ''); | ||
const modulejs = path_1.default.join('./node_modules', id, id.replace('-', '_') + '.js'); | ||
const code = await fs_extra_1.default.promises.readFile(modulejs, { | ||
encoding: 'utf-8' | ||
}); | ||
return code; | ||
} | ||
}, | ||
async buildStart(inputOptions) { | ||
for await (const cratePath of cratePaths) { | ||
const pkgPath = path_1.default.join(cratePath, 'pkg'); | ||
const pkgPath = path_1.default.join(cratePath, pkg); | ||
const crateName = path_1.default.basename(cratePath); | ||
@@ -57,2 +76,3 @@ if (!fs_extra_1.default.existsSync(pkgPath)) { | ||
const basename = path_1.default.basename(req.url); | ||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); | ||
if (basename.endsWith('.wasm') && wasmMap.get(basename) != null) { | ||
@@ -59,0 +79,0 @@ res.writeHead(200, { 'Content-Type': 'application/wasm' }); |
{ | ||
"name": "vite-plugin-wasm-pack", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "wasm-pack for Vite", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
8609
100