@squoosh-kit/vite-plugin 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -6
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyDA,MAAM,CAAC,OAAO,UAAU,iBAAiB;;;;;;;;;;;;;;;;;;;;;gDA0CD;wBAAE,IAAI,CAAC,EAAE,MAAM,CAAA;qBAAE;;;;;;EA2DxD"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
2
4
|
// src/index.ts
|
|
3
5
|
import {
|
|
4
6
|
existsSync,
|
|
@@ -8,7 +10,7 @@ import {
|
|
|
8
10
|
rmSync,
|
|
9
11
|
readFileSync
|
|
10
12
|
} from "fs";
|
|
11
|
-
import { join } from "path";
|
|
13
|
+
import { join, dirname } from "path";
|
|
12
14
|
import { searchForWorkspaceRoot } from "vite";
|
|
13
15
|
function copyBrowserFiles(srcDir, destDir) {
|
|
14
16
|
if (!existsSync(srcDir)) {
|
|
@@ -29,21 +31,36 @@ function copyBrowserFiles(srcDir, destDir) {
|
|
|
29
31
|
cpSync(wasmDir, destWasmDir, { recursive: true });
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
function resolvePackagePath(packageName, from) {
|
|
35
|
+
try {
|
|
36
|
+
const packageJsonPath = __require.resolve(`${packageName}/package.json`, {
|
|
37
|
+
paths: [from]
|
|
38
|
+
});
|
|
39
|
+
const packageDir = dirname(packageJsonPath);
|
|
40
|
+
return join(packageDir, "dist");
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn(`[squoosh-vite-plugin] Could not find package "${packageName}". It might not be installed. Skipping asset copy for this package.: ${err}`);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
32
46
|
function squooshVitePlugin() {
|
|
33
47
|
return {
|
|
34
48
|
name: "squoosh-vite-plugin",
|
|
35
49
|
buildStart() {
|
|
36
50
|
console.log("Copying Squoosh browser assets...");
|
|
37
51
|
const viteRoot = process.cwd();
|
|
38
|
-
const projectRoot = searchForWorkspaceRoot(viteRoot);
|
|
39
52
|
const publicDir = join(viteRoot, "public", "squoosh-kit");
|
|
40
|
-
const webpDist =
|
|
41
|
-
const resizeDist =
|
|
53
|
+
const webpDist = resolvePackagePath("@squoosh-kit/webp", viteRoot);
|
|
54
|
+
const resizeDist = resolvePackagePath("@squoosh-kit/resize", viteRoot);
|
|
42
55
|
if (existsSync(publicDir)) {
|
|
43
56
|
rmSync(publicDir, { recursive: true, force: true });
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
if (webpDist) {
|
|
59
|
+
copyBrowserFiles(webpDist, join(publicDir, "webp"));
|
|
60
|
+
}
|
|
61
|
+
if (resizeDist) {
|
|
62
|
+
copyBrowserFiles(resizeDist, join(publicDir, "resize"));
|
|
63
|
+
}
|
|
47
64
|
console.log("Squoosh assets copied successfully!");
|
|
48
65
|
},
|
|
49
66
|
config: () => ({
|
package/package.json
CHANGED