@hkdigital/lib-core 0.5.27 → 0.5.28
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.
|
@@ -146,7 +146,8 @@ export function generateResponseConfigs(options) {
|
|
|
146
146
|
...configPairs,
|
|
147
147
|
w: String(w),
|
|
148
148
|
format: 'png',
|
|
149
|
-
ensureAlpha: 'true'
|
|
149
|
+
ensureAlpha: 'true',
|
|
150
|
+
density: '300'
|
|
150
151
|
};
|
|
151
152
|
});
|
|
152
153
|
// console.log('**** Returning apple-touch-icon configs:', appleTouchConfigs);
|
|
@@ -63,10 +63,10 @@ export async function generateViteConfig(options = {}) {
|
|
|
63
63
|
if (enableImagetools) {
|
|
64
64
|
try {
|
|
65
65
|
const { imagetools } = await import('vite-imagetools');
|
|
66
|
-
const {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const { generateDefaultDirectives, generateResponseConfigs } =
|
|
67
|
+
await import('./imagetools.js');
|
|
68
|
+
|
|
69
|
+
const sharp = (await import('sharp')).default;
|
|
70
70
|
|
|
71
71
|
plugins.push(
|
|
72
72
|
imagetools({
|
|
@@ -77,33 +77,43 @@ export async function generateViteConfig(options = {}) {
|
|
|
77
77
|
enabled: false,
|
|
78
78
|
// enabled: true,
|
|
79
79
|
dir: './node_modules/.cache/imagetools',
|
|
80
|
-
retention: 60 * 60 * 24 * 10
|
|
80
|
+
retention: 60 * 60 * 24 * 10 // 10 days
|
|
81
81
|
},
|
|
82
82
|
// @see https://www.npmjs.com/package/vite-imagetools?activeTab=readme
|
|
83
|
+
// extendOutputFormats(builtins) {
|
|
84
|
+
// return {
|
|
85
|
+
// ...builtins,
|
|
86
|
+
// png: (config) => ({
|
|
87
|
+
// format: 'png',
|
|
88
|
+
// transform: (image) => image.withMetadata({ density: 300 })
|
|
89
|
+
// })
|
|
90
|
+
// };
|
|
91
|
+
// },
|
|
83
92
|
extendTransforms(builtins) {
|
|
84
93
|
const ensureAlphaTransform = (config, ctx) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Mark the parameter as used
|
|
91
|
-
ctx.useParam('ensureAlpha')
|
|
92
|
-
|
|
93
|
-
// Return the actual transformation function
|
|
94
|
-
return (image) => {
|
|
95
|
-
return image.ensureAlpha();
|
|
96
|
-
}
|
|
94
|
+
// Check if 'ensureAlpha' directive is in the URL
|
|
95
|
+
if (!('ensureAlpha' in config)) {
|
|
96
|
+
return undefined; // This transform doesn't apply
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
//
|
|
100
|
-
|
|
99
|
+
// Mark the parameter as used
|
|
100
|
+
ctx.useParam('ensureAlpha');
|
|
101
|
+
|
|
102
|
+
// Return the actual transformation function
|
|
103
|
+
return (image) => {
|
|
104
|
+
return image
|
|
105
|
+
.ensureAlpha()
|
|
106
|
+
.withMetadata({ xmp: '' });
|
|
107
|
+
};
|
|
108
|
+
};
|
|
101
109
|
|
|
110
|
+
// Return an ARRAY with builtins + your custom transform
|
|
111
|
+
return [...builtins, ensureAlphaTransform];
|
|
102
112
|
}
|
|
103
113
|
})
|
|
104
114
|
);
|
|
105
115
|
|
|
106
|
-
|
|
116
|
+
// eslint-disable-next-line no-unused-vars
|
|
107
117
|
} catch (error) {
|
|
108
118
|
const errorMessage = `
|
|
109
119
|
╭─────────────────────────────────────────────────────────────╮
|
|
@@ -114,7 +124,9 @@ export async function generateViteConfig(options = {}) {
|
|
|
114
124
|
│ Or set enableImagetools: false │
|
|
115
125
|
╰─────────────────────────────────────────────────────────────╯`;
|
|
116
126
|
console.error(errorMessage);
|
|
117
|
-
throw new Error(
|
|
127
|
+
throw new Error(
|
|
128
|
+
'vite-imagetools is required when enableImagetools: true'
|
|
129
|
+
);
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
|
|
@@ -126,7 +138,7 @@ export async function generateViteConfig(options = {}) {
|
|
|
126
138
|
new Date().toISOString()
|
|
127
139
|
),
|
|
128
140
|
...customDefines
|
|
129
|
-
}
|
|
141
|
+
}
|
|
130
142
|
};
|
|
131
143
|
|
|
132
144
|
if (enableVitest && !enableVitestWorkspace) {
|
|
@@ -187,10 +199,7 @@ export async function generateViteConfig(options = {}) {
|
|
|
187
199
|
* @returns {object} Define configuration object
|
|
188
200
|
*/
|
|
189
201
|
export function generateViteDefines(options = {}) {
|
|
190
|
-
const {
|
|
191
|
-
packageJsonPath = './package.json',
|
|
192
|
-
customDefines = {}
|
|
193
|
-
} = options;
|
|
202
|
+
const { packageJsonPath = './package.json', customDefines = {} } = options;
|
|
194
203
|
|
|
195
204
|
const packageJson = JSON.parse(
|
|
196
205
|
readFileSync(resolve(packageJsonPath), 'utf-8')
|