@squoosh-kit/vite-plugin 0.0.33 → 0.0.35
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 +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -6
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @squoosh-kit/vite-plugin
|
|
3
|
+
*
|
|
4
|
+
* Vite plugin that automatically configures squoosh-kit worker URLs.
|
|
5
|
+
* This plugin resolves worker paths using Vite's module resolution,
|
|
6
|
+
* ensuring workers load correctly in both development and production builds.
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'vite';
|
|
9
|
+
export interface SquooshKitPluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to auto-configure workers automatically.
|
|
12
|
+
* If true, configuration code is injected into entry points.
|
|
13
|
+
* If false, you must manually import '@squoosh-kit/vite-plugin/auto-config' in your app.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
autoConfigure?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Vite plugin for automatic squoosh-kit worker configuration.
|
|
20
|
+
*
|
|
21
|
+
* This plugin automatically resolves and configures worker URLs for
|
|
22
|
+
* @squoosh-kit/resize and @squoosh-kit/webp packages, ensuring they
|
|
23
|
+
* work correctly in both development and production builds.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // vite.config.ts
|
|
28
|
+
* import { defineConfig } from 'vite';
|
|
29
|
+
* import squooshKit from '@squoosh-kit/vite-plugin';
|
|
30
|
+
*
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* plugins: [squooshKit()],
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export default function squooshKit(options?: SquooshKitPluginOptions): Plugin;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAEnD,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAKD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAmGR"}
|
package/dist/index.js
CHANGED
|
@@ -84,12 +84,12 @@ function generateAutoConfigCode() {
|
|
|
84
84
|
return `// Auto-configured by @squoosh-kit/vite-plugin
|
|
85
85
|
import { configureResizeWorker } from '@squoosh-kit/resize';
|
|
86
86
|
import { configureWebpWorker } from '@squoosh-kit/webp';
|
|
87
|
+
// Use Vite's ?url import to get the worker file URLs
|
|
88
|
+
// Vite will resolve the package exports and return the URL
|
|
89
|
+
import resizeWorkerUrl from '@squoosh-kit/resize/resize.worker.js?url';
|
|
90
|
+
import webpWorkerUrl from '@squoosh-kit/webp/webp.worker.js?url';
|
|
87
91
|
|
|
88
|
-
//
|
|
89
|
-
const resizeWorkerUrl = new URL('@squoosh-kit/resize/dist/resize.worker.browser.mjs', import.meta.url).href;
|
|
90
|
-
const webpWorkerUrl = new URL('@squoosh-kit/webp/dist/webp.worker.browser.mjs', import.meta.url).href;
|
|
91
|
-
|
|
92
|
-
// Configure workers immediately
|
|
92
|
+
// Configure workers immediately with resolved URLs
|
|
93
93
|
configureResizeWorker(resizeWorkerUrl);
|
|
94
94
|
configureWebpWorker(webpWorkerUrl);`;
|
|
95
95
|
}
|
|
@@ -97,5 +97,5 @@ export {
|
|
|
97
97
|
squooshKit as default
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
//# debugId=
|
|
100
|
+
//# debugId=2059F9A824774FFD64756E2164756E21
|
|
101
101
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @squoosh-kit/vite-plugin\n *\n * Vite plugin that automatically configures squoosh-kit worker URLs.\n * This plugin resolves worker paths using Vite's module resolution,\n * ensuring workers load correctly in both development and production builds.\n */\n\nimport type { Plugin, ResolvedConfig } from 'vite';\n\nexport interface SquooshKitPluginOptions {\n /**\n * Whether to auto-configure workers automatically.\n * If true, configuration code is injected into entry points.\n * If false, you must manually import '@squoosh-kit/vite-plugin/auto-config' in your app.\n * @default true\n */\n autoConfigure?: boolean;\n}\n\nconst VIRTUAL_MODULE_ID = 'virtual:@squoosh-kit/vite-plugin/auto-config';\nconst RESOLVED_VIRTUAL_MODULE_ID = '\\0' + VIRTUAL_MODULE_ID;\n\n/**\n * Vite plugin for automatic squoosh-kit worker configuration.\n *\n * This plugin automatically resolves and configures worker URLs for\n * @squoosh-kit/resize and @squoosh-kit/webp packages, ensuring they\n * work correctly in both development and production builds.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import squooshKit from '@squoosh-kit/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [squooshKit()],\n * });\n * ```\n */\nexport default function squooshKit(\n options: SquooshKitPluginOptions = {}\n): Plugin {\n const { autoConfigure = true } = options;\n\n // Per-plugin-instance state\n const entryPoints = new Set<string>();\n let hasInjected = false;\n\n return {\n name: '@squoosh-kit/vite-plugin',\n enforce: 'pre',\n\n buildStart() {\n // Reset state for each build\n entryPoints.clear();\n hasInjected = false;\n },\n\n configResolved(config: ResolvedConfig) {\n // Track entry points from Vite config\n const input = config.build.rollupOptions.input;\n if (input) {\n if (typeof input === 'string') {\n entryPoints.add(input);\n } else if (Array.isArray(input)) {\n input.forEach((entry) => {\n if (typeof entry === 'string') {\n entryPoints.add(entry);\n }\n });\n } else {\n // Object format\n Object.values(input).forEach((entry) => {\n if (typeof entry === 'string') {\n entryPoints.add(entry);\n }\n });\n }\n }\n\n // Also track default entry points\n if (config.root) {\n const commonEntries = [\n 'src/main.ts',\n 'src/main.tsx',\n 'src/main.js',\n 'src/main.jsx',\n 'src/index.ts',\n 'src/index.tsx',\n 'src/index.js',\n 'src/index.jsx',\n 'src/app.ts',\n 'src/app.tsx',\n ];\n commonEntries.forEach((entry) => {\n entryPoints.add(entry);\n });\n }\n },\n\n resolveId(id: string) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateAutoConfigCode();\n }\n return null;\n },\n\n transform(code: string, id: string) {\n if (!autoConfigure || hasInjected) {\n return null;\n }\n\n // Check if this is an entry point\n const isEntryPoint =\n entryPoints.has(id) ||\n entryPoints.has(id.replace(/\\\\/g, '/')) ||\n /[/\\\\]src[/\\\\](main|index|app)\\.(ts|tsx|js|jsx)$/.test(id) ||\n (id.includes('main.') &&\n (code.includes('ReactDOM') || code.includes('createRoot')));\n\n // Only inject once at the first entry point\n if (isEntryPoint) {\n hasInjected = true;\n const configCode = generateAutoConfigCode();\n return {\n code: configCode + '\\n\\n' + code,\n map: null,\n };\n }\n\n return null;\n },\n };\n}\n\n/**\n * Generates the auto-configuration code that resolves and configures worker URLs.\n */\nfunction generateAutoConfigCode(): string {\n return `// Auto-configured by @squoosh-kit/vite-plugin\nimport { configureResizeWorker } from '@squoosh-kit/resize';\nimport { configureWebpWorker } from '@squoosh-kit/webp';\n
|
|
5
|
+
"/**\n * @squoosh-kit/vite-plugin\n *\n * Vite plugin that automatically configures squoosh-kit worker URLs.\n * This plugin resolves worker paths using Vite's module resolution,\n * ensuring workers load correctly in both development and production builds.\n */\n\nimport type { Plugin, ResolvedConfig } from 'vite';\n\nexport interface SquooshKitPluginOptions {\n /**\n * Whether to auto-configure workers automatically.\n * If true, configuration code is injected into entry points.\n * If false, you must manually import '@squoosh-kit/vite-plugin/auto-config' in your app.\n * @default true\n */\n autoConfigure?: boolean;\n}\n\nconst VIRTUAL_MODULE_ID = 'virtual:@squoosh-kit/vite-plugin/auto-config';\nconst RESOLVED_VIRTUAL_MODULE_ID = '\\0' + VIRTUAL_MODULE_ID;\n\n/**\n * Vite plugin for automatic squoosh-kit worker configuration.\n *\n * This plugin automatically resolves and configures worker URLs for\n * @squoosh-kit/resize and @squoosh-kit/webp packages, ensuring they\n * work correctly in both development and production builds.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import squooshKit from '@squoosh-kit/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [squooshKit()],\n * });\n * ```\n */\nexport default function squooshKit(\n options: SquooshKitPluginOptions = {}\n): Plugin {\n const { autoConfigure = true } = options;\n\n // Per-plugin-instance state\n const entryPoints = new Set<string>();\n let hasInjected = false;\n\n return {\n name: '@squoosh-kit/vite-plugin',\n enforce: 'pre',\n\n buildStart() {\n // Reset state for each build\n entryPoints.clear();\n hasInjected = false;\n },\n\n configResolved(config: ResolvedConfig) {\n // Track entry points from Vite config\n const input = config.build.rollupOptions.input;\n if (input) {\n if (typeof input === 'string') {\n entryPoints.add(input);\n } else if (Array.isArray(input)) {\n input.forEach((entry) => {\n if (typeof entry === 'string') {\n entryPoints.add(entry);\n }\n });\n } else {\n // Object format\n Object.values(input).forEach((entry) => {\n if (typeof entry === 'string') {\n entryPoints.add(entry);\n }\n });\n }\n }\n\n // Also track default entry points\n if (config.root) {\n const commonEntries = [\n 'src/main.ts',\n 'src/main.tsx',\n 'src/main.js',\n 'src/main.jsx',\n 'src/index.ts',\n 'src/index.tsx',\n 'src/index.js',\n 'src/index.jsx',\n 'src/app.ts',\n 'src/app.tsx',\n ];\n commonEntries.forEach((entry) => {\n entryPoints.add(entry);\n });\n }\n },\n\n resolveId(id: string) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateAutoConfigCode();\n }\n return null;\n },\n\n transform(code: string, id: string) {\n if (!autoConfigure || hasInjected) {\n return null;\n }\n\n // Check if this is an entry point\n const isEntryPoint =\n entryPoints.has(id) ||\n entryPoints.has(id.replace(/\\\\/g, '/')) ||\n /[/\\\\]src[/\\\\](main|index|app)\\.(ts|tsx|js|jsx)$/.test(id) ||\n (id.includes('main.') &&\n (code.includes('ReactDOM') || code.includes('createRoot')));\n\n // Only inject once at the first entry point\n if (isEntryPoint) {\n hasInjected = true;\n const configCode = generateAutoConfigCode();\n return {\n code: configCode + '\\n\\n' + code,\n map: null,\n };\n }\n\n return null;\n },\n };\n}\n\n/**\n * Generates the auto-configuration code that resolves and configures worker URLs.\n * Uses Vite's ?url import syntax to get the worker file URLs.\n */\nfunction generateAutoConfigCode(): string {\n return `// Auto-configured by @squoosh-kit/vite-plugin\nimport { configureResizeWorker } from '@squoosh-kit/resize';\nimport { configureWebpWorker } from '@squoosh-kit/webp';\n// Use Vite's ?url import to get the worker file URLs\n// Vite will resolve the package exports and return the URL\nimport resizeWorkerUrl from '@squoosh-kit/resize/resize.worker.js?url';\nimport webpWorkerUrl from '@squoosh-kit/webp/webp.worker.js?url';\n\n// Configure workers immediately with resolved URLs\nconfigureResizeWorker(resizeWorkerUrl);\nconfigureWebpWorker(webpWorkerUrl);`;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAoBA,IAAM,oBAAoB;AAC1B,IAAM,6BAA6B,SAAO;AAoB1C,SAAwB,UAAU,CAChC,UAAmC,CAAC,GAC5B;AAAA,EACR,QAAQ,gBAAgB,SAAS;AAAA,EAGjC,MAAM,cAAc,IAAI;AAAA,EACxB,IAAI,cAAc;AAAA,EAElB,OAAO;AAAA,IACL,MAAM;AAAA,IACN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