@squoosh-kit/vite-plugin 0.1.10 → 0.1.12

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 CHANGED
@@ -2,7 +2,7 @@ import type { ViteDevServer } from 'vite';
2
2
  export default function squooshVitePlugin(squooshKitRoot: string): {
3
3
  name: string;
4
4
  buildStart(this: import("rollup").PluginContext): void;
5
- config: (this: import("vite").ConfigPluginContext) => {
5
+ config: () => {
6
6
  server: {
7
7
  fs: {
8
8
  allow: string[];
@@ -17,7 +17,7 @@ export default function squooshVitePlugin(squooshKitRoot: string): {
17
17
  exclude: string[];
18
18
  };
19
19
  assetsInclude: string[];
20
- configureServer(server: ViteDevServer): void;
21
20
  };
21
+ configureServer(this: import("vite").MinimalPluginContextWithoutEnvironment, server: ViteDevServer): void;
22
22
  };
23
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AA+BxD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,cAAc,EAAE,MAAM;;;;;;;;;;;;;;;;;;gCAoClC,aAAa;;EA8C1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AA+BxD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,cAAc,EAAE,MAAM;;;;;;;;;;;;;;;;;;;yFAqCpC,aAAa;EAsDxC"}
package/dist/index.js CHANGED
@@ -61,41 +61,43 @@ function squooshVitePlugin(squooshKitRoot) {
61
61
  optimizeDeps: {
62
62
  exclude: ["@squoosh-kit/webp", "@squoosh-kit/resize"]
63
63
  },
64
- assetsInclude: ["**/*.wasm"],
65
- configureServer(server) {
66
- server.middlewares.use((req, res, next) => {
67
- const url = req.url;
68
- if (!url?.includes("squoosh-kit")) {
69
- next();
70
- return;
71
- }
72
- try {
73
- const cleanUrl = url.split("?")[0];
74
- const match = cleanUrl.match(/@squoosh-kit\/(webp|resize)\/(.*)/);
75
- if (match) {
76
- const [, packageName, filePath] = match;
77
- const resolvedPath = join(publicDir, packageName, filePath);
78
- if (existsSync(resolvedPath)) {
79
- const fileData = readFileSync(resolvedPath);
80
- if (resolvedPath.endsWith(".wasm")) {
81
- res.setHeader("Content-Type", "application/wasm");
82
- } else if (resolvedPath.endsWith(".js") || resolvedPath.endsWith(".mjs")) {
83
- res.setHeader("Content-Type", "application/javascript");
84
- }
85
- res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
86
- res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
87
- res.setHeader("Content-Length", fileData.length.toString());
88
- res.end(fileData);
89
- return;
90
- }
64
+ assetsInclude: ["**/*.wasm"]
65
+ }),
66
+ 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
+ const rewrittenUrl = url.replace(/@squoosh-kit\//, "/terst/");
74
+ if (rewrittenUrl !== url) {
75
+ req.url = rewrittenUrl;
76
+ }
77
+ next();
78
+ });
79
+ server.middlewares.use("/squoosh-kit", (req, res, next) => {
80
+ try {
81
+ const filePath = join(publicDir, req.url ?? "/");
82
+ if (existsSync(filePath)) {
83
+ const fileData = readFileSync(filePath);
84
+ if (filePath.endsWith(".wasm")) {
85
+ res.setHeader("Content-Type", "application/wasm");
86
+ } else if (filePath.endsWith(".js") || filePath.endsWith(".mjs")) {
87
+ res.setHeader("Content-Type", "application/javascript");
91
88
  }
92
- next();
93
- } catch {
94
- next();
89
+ res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
90
+ res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
91
+ res.setHeader("Content-Length", fileData.length.toString());
92
+ res.end(fileData);
93
+ return;
95
94
  }
96
- });
97
- }
98
- })
95
+ next();
96
+ } catch {
97
+ next();
98
+ }
99
+ });
100
+ }
99
101
  };
100
102
  }
101
103
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squoosh-kit/vite-plugin",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "description": "Vite plugin for Squoosh Kit - handles asset copying and WASM configuration",
6
6
  "author": "Bartosz Nowak <bnowak008@gmail.com>",