@squoosh-kit/vite-plugin 0.1.18 → 0.2.1
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/README.md +17 -13
- package/dist/index.cjs +182 -0
- package/dist/index.d.ts +1 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -21
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40squoosh-kit%2Fvite-plugin)
|
|
4
4
|
[](https://bun.sh/)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
|
|
8
|
-
A Vite plugin for Squoosh
|
|
8
|
+
A Vite plugin for Squoosh-Kit that handles asset copying and WebAssembly configuration.
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
11
|
|
|
12
|
-
The `@squoosh-kit/vite-plugin` simplifies integrating Squoosh
|
|
12
|
+
The `@squoosh-kit/vite-plugin` simplifies integrating Squoosh-Kit codecs into Vite projects by:
|
|
13
13
|
|
|
14
14
|
- **Automatically copying browser-compatible assets** from `@squoosh-kit/webp` and `@squoosh-kit/resize` packages
|
|
15
15
|
- **Configuring WASM module handling** with proper MIME types and CORS headers
|
|
@@ -32,15 +32,16 @@ Add the plugin to your `vite.config.ts`:
|
|
|
32
32
|
import { defineConfig } from 'vite';
|
|
33
33
|
import react from '@vitejs/plugin-react';
|
|
34
34
|
import squooshVitePlugin from '@squoosh-kit/vite-plugin';
|
|
35
|
+
import { resolve } from 'path';
|
|
35
36
|
|
|
36
37
|
export default defineConfig({
|
|
37
|
-
plugins: [react(), squooshVitePlugin()],
|
|
38
|
+
plugins: [react(), squooshVitePlugin(resolve('node_modules/@squoosh-kit'))],
|
|
38
39
|
});
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
That's it! The plugin will:
|
|
42
43
|
|
|
43
|
-
1. Copy Squoosh
|
|
44
|
+
1. Copy Squoosh-Kit browser assets to your `public/squoosh-kit` directory
|
|
44
45
|
2. Configure Vite to properly handle WASM files
|
|
45
46
|
3. Set necessary CORS headers for cross-origin embedder policy
|
|
46
47
|
4. Exclude heavy dependencies from optimization
|
|
@@ -78,7 +79,7 @@ In development mode, the plugin:
|
|
|
78
79
|
|
|
79
80
|
## Usage Example
|
|
80
81
|
|
|
81
|
-
After setting up the plugin, you can use Squoosh
|
|
82
|
+
After setting up the plugin, you can use Squoosh-Kit as normal:
|
|
82
83
|
|
|
83
84
|
```typescript
|
|
84
85
|
import { createWebpEncoder, createResizer } from '@squoosh-kit/core';
|
|
@@ -99,11 +100,13 @@ const resizedImage = await resizer(imageData, { width: 800 });
|
|
|
99
100
|
|
|
100
101
|
## API Reference
|
|
101
102
|
|
|
102
|
-
### `squooshVitePlugin()`
|
|
103
|
+
### `squooshVitePlugin(squooshKitRoot)`
|
|
103
104
|
|
|
104
|
-
Returns a Vite plugin that configures Squoosh
|
|
105
|
+
Returns a Vite plugin that configures Squoosh-Kit integration.
|
|
105
106
|
|
|
106
|
-
**Parameters:**
|
|
107
|
+
**Parameters:**
|
|
108
|
+
|
|
109
|
+
- `squooshKitRoot: string` — Path to the `@squoosh-kit` directory inside `node_modules`. The plugin uses this to locate the `webp/dist` and `resize/dist` directories for asset copying.
|
|
107
110
|
|
|
108
111
|
**Returns:** Vite Plugin
|
|
109
112
|
|
|
@@ -111,9 +114,10 @@ Returns a Vite plugin that configures Squoosh Kit integration.
|
|
|
111
114
|
|
|
112
115
|
```typescript
|
|
113
116
|
import squooshVitePlugin from '@squoosh-kit/vite-plugin';
|
|
117
|
+
import { resolve } from 'path';
|
|
114
118
|
|
|
115
119
|
export default defineConfig({
|
|
116
|
-
plugins: [squooshVitePlugin()],
|
|
120
|
+
plugins: [squooshVitePlugin(resolve('node_modules/@squoosh-kit'))],
|
|
117
121
|
});
|
|
118
122
|
```
|
|
119
123
|
|
|
@@ -179,7 +183,7 @@ Check that:
|
|
|
179
183
|
|
|
180
184
|
### Build fails with "dist not found"
|
|
181
185
|
|
|
182
|
-
Ensure you've built the Squoosh
|
|
186
|
+
Ensure you've built the Squoosh-Kit packages first:
|
|
183
187
|
|
|
184
188
|
```bash
|
|
185
189
|
bun run build
|
|
@@ -194,7 +198,7 @@ bun run build
|
|
|
194
198
|
|
|
195
199
|
## Architecture
|
|
196
200
|
|
|
197
|
-
The plugin follows Squoosh
|
|
201
|
+
The plugin follows Squoosh-Kit principles:
|
|
198
202
|
|
|
199
203
|
- **Minimal and focused**: Handles only WASM and asset configuration
|
|
200
204
|
- **Framework agnostic**: Works with any Vite-based framework
|
|
@@ -203,4 +207,4 @@ The plugin follows Squoosh Kit principles:
|
|
|
203
207
|
|
|
204
208
|
## License
|
|
205
209
|
|
|
206
|
-
MIT - part of the Squoosh
|
|
210
|
+
MIT - part of the Squoosh-Kit family
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
function __accessProp(key) {
|
|
7
|
+
return this[key];
|
|
8
|
+
}
|
|
9
|
+
var __toCommonJS = (from) => {
|
|
10
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
11
|
+
if (entry)
|
|
12
|
+
return entry;
|
|
13
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (var key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(entry, key))
|
|
17
|
+
__defProp(entry, key, {
|
|
18
|
+
get: __accessProp.bind(from, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
__moduleCache.set(from, entry);
|
|
23
|
+
return entry;
|
|
24
|
+
};
|
|
25
|
+
var __moduleCache;
|
|
26
|
+
var __returnValue = (v) => v;
|
|
27
|
+
function __exportSetter(name, newValue) {
|
|
28
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
29
|
+
}
|
|
30
|
+
var __export = (target, all) => {
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, {
|
|
33
|
+
get: all[name],
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
set: __exportSetter.bind(all, name)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/index.ts
|
|
41
|
+
var exports_src = {};
|
|
42
|
+
__export(exports_src, {
|
|
43
|
+
default: () => squooshVitePlugin
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_src);
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
function copyBrowserFiles(srcDir, destDir) {
|
|
49
|
+
if (!import_fs.existsSync(srcDir)) {
|
|
50
|
+
console.warn(`Source directory does not exist: ${srcDir}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
import_fs.mkdirSync(destDir, { recursive: true });
|
|
54
|
+
const files = import_fs.readdirSync(srcDir);
|
|
55
|
+
const browserFiles = files.filter((file) => file.endsWith(".browser.mjs") || file.endsWith(".browser.mjs.map") || file.endsWith(".d.ts") || file.endsWith(".d.ts.map"));
|
|
56
|
+
for (const file of browserFiles) {
|
|
57
|
+
const srcPath = import_path.join(srcDir, file);
|
|
58
|
+
const destPath = import_path.join(destDir, file);
|
|
59
|
+
import_fs.cpSync(srcPath, destPath);
|
|
60
|
+
}
|
|
61
|
+
const wasmDir = import_path.join(srcDir, "wasm");
|
|
62
|
+
if (import_fs.existsSync(wasmDir)) {
|
|
63
|
+
const destWasmDir = import_path.join(destDir, "wasm");
|
|
64
|
+
import_fs.cpSync(wasmDir, destWasmDir, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function squooshVitePlugin(squooshKitRoot) {
|
|
68
|
+
const viteRoot = process.cwd();
|
|
69
|
+
const publicDir = import_path.join(viteRoot, "public", "squoosh-kit");
|
|
70
|
+
const webpDist = import_path.join(squooshKitRoot, "webp", "dist");
|
|
71
|
+
const resizeDist = import_path.join(squooshKitRoot, "resize", "dist");
|
|
72
|
+
const avifDist = import_path.join(squooshKitRoot, "avif", "dist");
|
|
73
|
+
const mozjpegDist = import_path.join(squooshKitRoot, "mozjpeg", "dist");
|
|
74
|
+
const jxlDist = import_path.join(squooshKitRoot, "jxl", "dist");
|
|
75
|
+
const oxipngDist = import_path.join(squooshKitRoot, "oxipng", "dist");
|
|
76
|
+
const imagequantDist = import_path.join(squooshKitRoot, "imagequant", "dist");
|
|
77
|
+
const pngDist = import_path.join(squooshKitRoot, "png", "dist");
|
|
78
|
+
const qoiDist = import_path.join(squooshKitRoot, "qoi", "dist");
|
|
79
|
+
const wp2Dist = import_path.join(squooshKitRoot, "wp2", "dist");
|
|
80
|
+
const hqxDist = import_path.join(squooshKitRoot, "hqx", "dist");
|
|
81
|
+
const rotateDist = import_path.join(squooshKitRoot, "rotate", "dist");
|
|
82
|
+
const visdifDist = import_path.join(squooshKitRoot, "visdif", "dist");
|
|
83
|
+
return {
|
|
84
|
+
name: "squoosh-vite-plugin",
|
|
85
|
+
buildStart() {
|
|
86
|
+
if (import_fs.existsSync(publicDir)) {
|
|
87
|
+
import_fs.rmSync(publicDir, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
if (import_fs.existsSync(webpDist)) {
|
|
90
|
+
copyBrowserFiles(webpDist, import_path.join(publicDir, "webp"));
|
|
91
|
+
}
|
|
92
|
+
if (import_fs.existsSync(resizeDist)) {
|
|
93
|
+
copyBrowserFiles(resizeDist, import_path.join(publicDir, "resize"));
|
|
94
|
+
}
|
|
95
|
+
if (import_fs.existsSync(avifDist)) {
|
|
96
|
+
copyBrowserFiles(avifDist, import_path.join(publicDir, "avif"));
|
|
97
|
+
}
|
|
98
|
+
if (import_fs.existsSync(mozjpegDist)) {
|
|
99
|
+
copyBrowserFiles(mozjpegDist, import_path.join(publicDir, "mozjpeg"));
|
|
100
|
+
}
|
|
101
|
+
if (import_fs.existsSync(jxlDist)) {
|
|
102
|
+
copyBrowserFiles(jxlDist, import_path.join(publicDir, "jxl"));
|
|
103
|
+
}
|
|
104
|
+
if (import_fs.existsSync(oxipngDist)) {
|
|
105
|
+
copyBrowserFiles(oxipngDist, import_path.join(publicDir, "oxipng"));
|
|
106
|
+
}
|
|
107
|
+
if (import_fs.existsSync(imagequantDist)) {
|
|
108
|
+
copyBrowserFiles(imagequantDist, import_path.join(publicDir, "imagequant"));
|
|
109
|
+
}
|
|
110
|
+
if (import_fs.existsSync(pngDist)) {
|
|
111
|
+
copyBrowserFiles(pngDist, import_path.join(publicDir, "png"));
|
|
112
|
+
}
|
|
113
|
+
if (import_fs.existsSync(qoiDist)) {
|
|
114
|
+
copyBrowserFiles(qoiDist, import_path.join(publicDir, "qoi"));
|
|
115
|
+
}
|
|
116
|
+
if (import_fs.existsSync(wp2Dist)) {
|
|
117
|
+
copyBrowserFiles(wp2Dist, import_path.join(publicDir, "wp2"));
|
|
118
|
+
}
|
|
119
|
+
if (import_fs.existsSync(hqxDist)) {
|
|
120
|
+
copyBrowserFiles(hqxDist, import_path.join(publicDir, "hqx"));
|
|
121
|
+
}
|
|
122
|
+
if (import_fs.existsSync(rotateDist)) {
|
|
123
|
+
copyBrowserFiles(rotateDist, import_path.join(publicDir, "rotate"));
|
|
124
|
+
}
|
|
125
|
+
if (import_fs.existsSync(visdifDist)) {
|
|
126
|
+
copyBrowserFiles(visdifDist, import_path.join(publicDir, "visdif"));
|
|
127
|
+
}
|
|
128
|
+
console.log("Squoosh assets copied successfully!");
|
|
129
|
+
},
|
|
130
|
+
config: () => ({
|
|
131
|
+
server: {
|
|
132
|
+
headers: {
|
|
133
|
+
"Cross-Origin-Embedder-Policy": "credentialless",
|
|
134
|
+
"Cross-Origin-Opener-Policy": "same-origin",
|
|
135
|
+
"Access-Control-Allow-Origin": "*"
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
optimizeDeps: {
|
|
139
|
+
exclude: [
|
|
140
|
+
"@squoosh-kit/webp",
|
|
141
|
+
"@squoosh-kit/resize",
|
|
142
|
+
"@squoosh-kit/avif",
|
|
143
|
+
"@squoosh-kit/mozjpeg",
|
|
144
|
+
"@squoosh-kit/jxl",
|
|
145
|
+
"@squoosh-kit/oxipng",
|
|
146
|
+
"@squoosh-kit/imagequant",
|
|
147
|
+
"@squoosh-kit/png",
|
|
148
|
+
"@squoosh-kit/qoi",
|
|
149
|
+
"@squoosh-kit/wp2",
|
|
150
|
+
"@squoosh-kit/hqx",
|
|
151
|
+
"@squoosh-kit/rotate",
|
|
152
|
+
"@squoosh-kit/visdif"
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
assetsInclude: ["**/*.wasm"]
|
|
156
|
+
}),
|
|
157
|
+
configureServer(server) {
|
|
158
|
+
server.middlewares.use("/squoosh-kit", (req, res, next) => {
|
|
159
|
+
try {
|
|
160
|
+
const filePath = import_path.join(publicDir, req.url ?? "/");
|
|
161
|
+
if (import_fs.existsSync(filePath)) {
|
|
162
|
+
const fileData = import_fs.readFileSync(filePath);
|
|
163
|
+
if (filePath.endsWith(".wasm")) {
|
|
164
|
+
res.setHeader("Content-Type", "application/wasm");
|
|
165
|
+
} else if (filePath.endsWith(".js") || filePath.endsWith(".mjs")) {
|
|
166
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
167
|
+
}
|
|
168
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "credentialless");
|
|
169
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
170
|
+
res.setHeader("Content-Length", fileData.length.toString());
|
|
171
|
+
res.end(fileData);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
next();
|
|
175
|
+
} catch {
|
|
176
|
+
next();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
})
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function squooshVitePlugin(squooshKitRoot: string): {
|
|
3
|
-
name: string;
|
|
4
|
-
buildStart(this: import("rollup").PluginContext): void;
|
|
5
|
-
config: () => {
|
|
6
|
-
server: {
|
|
7
|
-
fs: {
|
|
8
|
-
allow: string[];
|
|
9
|
-
};
|
|
10
|
-
headers: {
|
|
11
|
-
'Cross-Origin-Embedder-Policy': string;
|
|
12
|
-
'Cross-Origin-Opener-Policy': string;
|
|
13
|
-
'Access-Control-Allow-Origin': string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
optimizeDeps: {
|
|
17
|
-
exclude: string[];
|
|
18
|
-
};
|
|
19
|
-
assetsInclude: string[];
|
|
20
|
-
};
|
|
21
|
-
configureServer(this: import("vite").MinimalPluginContextWithoutEnvironment, server: ViteDevServer): void;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export default function squooshVitePlugin(squooshKitRoot: string): { name: string };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,MAAM,CAAC;AAgCxD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,cAAc,EAAE,MAAM,GACrB,YAAY,CA+Hd"}
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,17 @@ function squooshVitePlugin(squooshKitRoot) {
|
|
|
33
33
|
const publicDir = join(viteRoot, "public", "squoosh-kit");
|
|
34
34
|
const webpDist = join(squooshKitRoot, "webp", "dist");
|
|
35
35
|
const resizeDist = join(squooshKitRoot, "resize", "dist");
|
|
36
|
+
const avifDist = join(squooshKitRoot, "avif", "dist");
|
|
37
|
+
const mozjpegDist = join(squooshKitRoot, "mozjpeg", "dist");
|
|
38
|
+
const jxlDist = join(squooshKitRoot, "jxl", "dist");
|
|
39
|
+
const oxipngDist = join(squooshKitRoot, "oxipng", "dist");
|
|
40
|
+
const imagequantDist = join(squooshKitRoot, "imagequant", "dist");
|
|
41
|
+
const pngDist = join(squooshKitRoot, "png", "dist");
|
|
42
|
+
const qoiDist = join(squooshKitRoot, "qoi", "dist");
|
|
43
|
+
const wp2Dist = join(squooshKitRoot, "wp2", "dist");
|
|
44
|
+
const hqxDist = join(squooshKitRoot, "hqx", "dist");
|
|
45
|
+
const rotateDist = join(squooshKitRoot, "rotate", "dist");
|
|
46
|
+
const visdifDist = join(squooshKitRoot, "visdif", "dist");
|
|
36
47
|
return {
|
|
37
48
|
name: "squoosh-vite-plugin",
|
|
38
49
|
buildStart() {
|
|
@@ -45,40 +56,69 @@ function squooshVitePlugin(squooshKitRoot) {
|
|
|
45
56
|
if (existsSync(resizeDist)) {
|
|
46
57
|
copyBrowserFiles(resizeDist, join(publicDir, "resize"));
|
|
47
58
|
}
|
|
59
|
+
if (existsSync(avifDist)) {
|
|
60
|
+
copyBrowserFiles(avifDist, join(publicDir, "avif"));
|
|
61
|
+
}
|
|
62
|
+
if (existsSync(mozjpegDist)) {
|
|
63
|
+
copyBrowserFiles(mozjpegDist, join(publicDir, "mozjpeg"));
|
|
64
|
+
}
|
|
65
|
+
if (existsSync(jxlDist)) {
|
|
66
|
+
copyBrowserFiles(jxlDist, join(publicDir, "jxl"));
|
|
67
|
+
}
|
|
68
|
+
if (existsSync(oxipngDist)) {
|
|
69
|
+
copyBrowserFiles(oxipngDist, join(publicDir, "oxipng"));
|
|
70
|
+
}
|
|
71
|
+
if (existsSync(imagequantDist)) {
|
|
72
|
+
copyBrowserFiles(imagequantDist, join(publicDir, "imagequant"));
|
|
73
|
+
}
|
|
74
|
+
if (existsSync(pngDist)) {
|
|
75
|
+
copyBrowserFiles(pngDist, join(publicDir, "png"));
|
|
76
|
+
}
|
|
77
|
+
if (existsSync(qoiDist)) {
|
|
78
|
+
copyBrowserFiles(qoiDist, join(publicDir, "qoi"));
|
|
79
|
+
}
|
|
80
|
+
if (existsSync(wp2Dist)) {
|
|
81
|
+
copyBrowserFiles(wp2Dist, join(publicDir, "wp2"));
|
|
82
|
+
}
|
|
83
|
+
if (existsSync(hqxDist)) {
|
|
84
|
+
copyBrowserFiles(hqxDist, join(publicDir, "hqx"));
|
|
85
|
+
}
|
|
86
|
+
if (existsSync(rotateDist)) {
|
|
87
|
+
copyBrowserFiles(rotateDist, join(publicDir, "rotate"));
|
|
88
|
+
}
|
|
89
|
+
if (existsSync(visdifDist)) {
|
|
90
|
+
copyBrowserFiles(visdifDist, join(publicDir, "visdif"));
|
|
91
|
+
}
|
|
48
92
|
console.log("Squoosh assets copied successfully!");
|
|
49
93
|
},
|
|
50
94
|
config: () => ({
|
|
51
95
|
server: {
|
|
52
|
-
fs: {
|
|
53
|
-
allow: [viteRoot, squooshKitRoot]
|
|
54
|
-
},
|
|
55
96
|
headers: {
|
|
56
|
-
"Cross-Origin-Embedder-Policy": "
|
|
97
|
+
"Cross-Origin-Embedder-Policy": "credentialless",
|
|
57
98
|
"Cross-Origin-Opener-Policy": "same-origin",
|
|
58
99
|
"Access-Control-Allow-Origin": "*"
|
|
59
100
|
}
|
|
60
101
|
},
|
|
61
102
|
optimizeDeps: {
|
|
62
|
-
exclude: [
|
|
103
|
+
exclude: [
|
|
104
|
+
"@squoosh-kit/webp",
|
|
105
|
+
"@squoosh-kit/resize",
|
|
106
|
+
"@squoosh-kit/avif",
|
|
107
|
+
"@squoosh-kit/mozjpeg",
|
|
108
|
+
"@squoosh-kit/jxl",
|
|
109
|
+
"@squoosh-kit/oxipng",
|
|
110
|
+
"@squoosh-kit/imagequant",
|
|
111
|
+
"@squoosh-kit/png",
|
|
112
|
+
"@squoosh-kit/qoi",
|
|
113
|
+
"@squoosh-kit/wp2",
|
|
114
|
+
"@squoosh-kit/hqx",
|
|
115
|
+
"@squoosh-kit/rotate",
|
|
116
|
+
"@squoosh-kit/visdif"
|
|
117
|
+
]
|
|
63
118
|
},
|
|
64
119
|
assetsInclude: ["**/*.wasm"]
|
|
65
120
|
}),
|
|
66
121
|
configureServer(server) {
|
|
67
|
-
server.middlewares.use((req, res, next) => {
|
|
68
|
-
const url = req.url;
|
|
69
|
-
if (!url?.includes("squoosh-kit")) {
|
|
70
|
-
next();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
let rewrittenUrl = url;
|
|
74
|
-
if (url.includes("@squoosh-kit")) {
|
|
75
|
-
rewrittenUrl = "/squoosh-kit" + url.split("@squoosh-kit")[1].replace("/dist", "").split("?")[0];
|
|
76
|
-
} else {
|
|
77
|
-
rewrittenUrl = "/squoosh-kit" + url.split("squoosh-kit")[1].replace("/dist", "").split("?")[0];
|
|
78
|
-
}
|
|
79
|
-
req.url = rewrittenUrl;
|
|
80
|
-
next();
|
|
81
|
-
});
|
|
82
122
|
server.middlewares.use("/squoosh-kit", (req, res, next) => {
|
|
83
123
|
try {
|
|
84
124
|
const filePath = join(publicDir, req.url ?? "/");
|
|
@@ -89,7 +129,7 @@ function squooshVitePlugin(squooshKitRoot) {
|
|
|
89
129
|
} else if (filePath.endsWith(".js") || filePath.endsWith(".mjs")) {
|
|
90
130
|
res.setHeader("Content-Type", "application/javascript");
|
|
91
131
|
}
|
|
92
|
-
res.setHeader("Cross-Origin-Embedder-Policy", "
|
|
132
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "credentialless");
|
|
93
133
|
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
94
134
|
res.setHeader("Content-Length", fileData.length.toString());
|
|
95
135
|
res.end(fileData);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squoosh-kit/vite-plugin",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Vite plugin for Squoosh
|
|
5
|
+
"description": "Vite plugin for Squoosh-Kit - handles asset copying and WASM configuration",
|
|
6
6
|
"author": "Bartosz Nowak <bnowak008@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "bunx tsc -p . && bun build ./src/index.ts --outdir dist --format esm --target bun --external vite",
|
|
33
|
+
"build": "bunx tsc -p . && bun build ./src/index.ts --outdir dist --format esm --target bun --external vite && bun build ./src/index.ts --outfile dist/index.cjs --format cjs --target bun --external vite && printf 'export default function squooshVitePlugin(squooshKitRoot: string): { name: string };\\n' > dist/index.d.ts",
|
|
34
34
|
"clean": "rm -rf dist node_modules .bun/install/cache bun.lockb bun.lock *.tsbuildinfo",
|
|
35
35
|
"prepublishOnly": "bun run build",
|
|
36
36
|
"typecheck": "tsc --noEmit"
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/bun": "latest",
|
|
40
40
|
"typescript": "~5.9.3",
|
|
41
|
-
"vite": "^7.
|
|
41
|
+
"vite": "^7.3.1"
|
|
42
42
|
}
|
|
43
43
|
}
|