@squoosh-kit/vite-plugin 0.2.2 → 0.2.4

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.cjs CHANGED
@@ -45,6 +45,47 @@ __export(exports_src, {
45
45
  module.exports = __toCommonJS(exports_src);
46
46
  var import_fs = require("fs");
47
47
  var import_path = require("path");
48
+ var import_vite = require("vite");
49
+ var SQUOOSH_CODEC_PACKAGE_NAMES = [
50
+ "webp",
51
+ "resize",
52
+ "avif",
53
+ "mozjpeg",
54
+ "jxl",
55
+ "oxipng",
56
+ "imagequant",
57
+ "png",
58
+ "qoi",
59
+ "wp2",
60
+ "hqx",
61
+ "rotate",
62
+ "visdif"
63
+ ];
64
+ var SQUOOSH_CODEC_WORKSPACE_BROWSER_RE = new RegExp(`[/\\\\]packages[/\\\\](?:${SQUOOSH_CODEC_PACKAGE_NAMES.join("|")})[/\\\\]dist[/\\\\]index\\.browser\\.mjs`);
65
+ function shouldSuppressSquooshKitDynamicImportAnalysisWarn(msg) {
66
+ if (!msg.includes("dynamic import cannot be analyzed")) {
67
+ return false;
68
+ }
69
+ if (msg.includes("@squoosh-kit")) {
70
+ return true;
71
+ }
72
+ return SQUOOSH_CODEC_WORKSPACE_BROWSER_RE.test(msg);
73
+ }
74
+ function withSquooshKitCodecImportWarningsFiltered(base) {
75
+ return new Proxy(base, {
76
+ get(target, prop, receiver) {
77
+ if (prop === "warn" || prop === "warnOnce") {
78
+ return (msg, options) => {
79
+ if (shouldSuppressSquooshKitDynamicImportAnalysisWarn(msg)) {
80
+ return;
81
+ }
82
+ return Reflect.get(target, prop, receiver).call(target, msg, options);
83
+ };
84
+ }
85
+ return Reflect.get(target, prop, receiver);
86
+ }
87
+ });
88
+ }
48
89
  function copyBrowserFiles(srcDir, destDir) {
49
90
  if (!import_fs.existsSync(srcDir)) {
50
91
  console.warn(`Source directory does not exist: ${srcDir}`);
@@ -127,7 +168,8 @@ function squooshVitePlugin(squooshKitRoot) {
127
168
  }
128
169
  console.log("Squoosh assets copied successfully!");
129
170
  },
130
- config: () => ({
171
+ config: (config) => ({
172
+ customLogger: withSquooshKitCodecImportWarningsFiltered(config.customLogger ?? import_vite.createLogger(config.logLevel)),
131
173
  server: {
132
174
  headers: {
133
175
  "Cross-Origin-Embedder-Policy": "credentialless",
@@ -136,21 +178,7 @@ function squooshVitePlugin(squooshKitRoot) {
136
178
  }
137
179
  },
138
180
  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
- ]
181
+ exclude: SQUOOSH_CODEC_PACKAGE_NAMES.map((name) => `@squoosh-kit/${name}`)
154
182
  },
155
183
  assetsInclude: ["**/*.wasm"]
156
184
  }),
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAU,YAAY,EAA6B,MAAM,MAAM,CAAC;AAgF5E,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,cAAc,EAAE,MAAM,GACrB,YAAY,CAsHd"}
package/dist/index.js CHANGED
@@ -9,6 +9,47 @@ import {
9
9
  readFileSync
10
10
  } from "fs";
11
11
  import { join } from "path";
12
+ import { createLogger } from "vite";
13
+ var SQUOOSH_CODEC_PACKAGE_NAMES = [
14
+ "webp",
15
+ "resize",
16
+ "avif",
17
+ "mozjpeg",
18
+ "jxl",
19
+ "oxipng",
20
+ "imagequant",
21
+ "png",
22
+ "qoi",
23
+ "wp2",
24
+ "hqx",
25
+ "rotate",
26
+ "visdif"
27
+ ];
28
+ var SQUOOSH_CODEC_WORKSPACE_BROWSER_RE = new RegExp(`[/\\\\]packages[/\\\\](?:${SQUOOSH_CODEC_PACKAGE_NAMES.join("|")})[/\\\\]dist[/\\\\]index\\.browser\\.mjs`);
29
+ function shouldSuppressSquooshKitDynamicImportAnalysisWarn(msg) {
30
+ if (!msg.includes("dynamic import cannot be analyzed")) {
31
+ return false;
32
+ }
33
+ if (msg.includes("@squoosh-kit")) {
34
+ return true;
35
+ }
36
+ return SQUOOSH_CODEC_WORKSPACE_BROWSER_RE.test(msg);
37
+ }
38
+ function withSquooshKitCodecImportWarningsFiltered(base) {
39
+ return new Proxy(base, {
40
+ get(target, prop, receiver) {
41
+ if (prop === "warn" || prop === "warnOnce") {
42
+ return (msg, options) => {
43
+ if (shouldSuppressSquooshKitDynamicImportAnalysisWarn(msg)) {
44
+ return;
45
+ }
46
+ return Reflect.get(target, prop, receiver).call(target, msg, options);
47
+ };
48
+ }
49
+ return Reflect.get(target, prop, receiver);
50
+ }
51
+ });
52
+ }
12
53
  function copyBrowserFiles(srcDir, destDir) {
13
54
  if (!existsSync(srcDir)) {
14
55
  console.warn(`Source directory does not exist: ${srcDir}`);
@@ -91,7 +132,8 @@ function squooshVitePlugin(squooshKitRoot) {
91
132
  }
92
133
  console.log("Squoosh assets copied successfully!");
93
134
  },
94
- config: () => ({
135
+ config: (config) => ({
136
+ customLogger: withSquooshKitCodecImportWarningsFiltered(config.customLogger ?? createLogger(config.logLevel)),
95
137
  server: {
96
138
  headers: {
97
139
  "Cross-Origin-Embedder-Policy": "credentialless",
@@ -100,21 +142,7 @@ function squooshVitePlugin(squooshKitRoot) {
100
142
  }
101
143
  },
102
144
  optimizeDeps: {
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
- ]
145
+ exclude: SQUOOSH_CODEC_PACKAGE_NAMES.map((name) => `@squoosh-kit/${name}`)
118
146
  },
119
147
  assetsInclude: ["**/*.wasm"]
120
148
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squoosh-kit/vite-plugin",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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>",