vatts 1.1.2 → 1.1.3

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.
Files changed (2) hide show
  1. package/dist/builder.js +7 -55
  2. package/package.json +1 -1
package/dist/builder.js CHANGED
@@ -20,14 +20,6 @@ const path = require('path');
20
20
  const Console = require("./api/console").default;
21
21
  const fs = require('fs');
22
22
  const { readdir, stat, rm } = require("node:fs/promises");
23
- // Tenta carregar o Sharp para otimização de imagens
24
- let sharp;
25
- try {
26
- sharp = require('sharp');
27
- }
28
- catch (e) {
29
- Console.warn("Sharp não encontrado. Otimização de imagem (resize) desativada. Instale com: npm install sharp");
30
- }
31
23
  // Plugins Oficiais do Rollup
32
24
  const nodeResolve = require('@rollup/plugin-node-resolve').default;
33
25
  const commonjs = require('@rollup/plugin-commonjs').default;
@@ -210,8 +202,8 @@ const customPostCssPlugin = (isProduction) => {
210
202
  };
211
203
  };
212
204
  /**
213
- * Plugin Inteligente para Assets (Otimizado para RAM e agora com Sharp)
214
- * - Suporta redimensionamento via query params: import img from './image.png?w=200&h=200'
205
+ * Plugin Inteligente para Assets (Otimizado para RAM)
206
+ * - Agora utiliza emissão de arquivos também em DEV para arquivos grandes.
215
207
  */
216
208
  const smartAssetPlugin = (isProduction) => {
217
209
  // 4KB - Arquivos maiores que isso viram referência externa.
@@ -220,8 +212,7 @@ const smartAssetPlugin = (isProduction) => {
220
212
  return {
221
213
  name: 'smart-asset-loader',
222
214
  async load(id) {
223
- // Separa o ID dos parâmetros de query
224
- const [cleanId, queryParams] = id.split('?');
215
+ const cleanId = id.split('?')[0];
225
216
  if (cleanId.startsWith('\0'))
226
217
  return null;
227
218
  const ext = path.extname(cleanId).slice(1).toLowerCase();
@@ -245,46 +236,6 @@ const smartAssetPlugin = (isProduction) => {
245
236
  return `export default ${JSON.stringify(content)};`;
246
237
  }
247
238
  let buffer = await fs.promises.readFile(cleanId);
248
- // --- VATTS IMAGE OPTIMIZATION (SHARP) ---
249
- // Verifica se tem sharp e se tem parâmetros de resize (w=, h=, q=)
250
- if (sharp && queryParams && ['png', 'jpg', 'jpeg', 'webp', 'avif'].includes(ext)) {
251
- try {
252
- const params = new URLSearchParams(queryParams);
253
- const width = params.get('w') || params.get('width');
254
- const height = params.get('h') || params.get('height');
255
- const quality = params.get('q') || params.get('quality');
256
- if (width || height || quality) {
257
- let transformer = sharp(buffer);
258
- if (width || height) {
259
- transformer = transformer.resize({
260
- width: width ? parseInt(width) : null,
261
- height: height ? parseInt(height) : null,
262
- fit: 'cover', // Padrão 'cover' para manter aspect ratio preenchendo
263
- withoutEnlargement: true // Não aumenta se a imagem original for menor
264
- });
265
- }
266
- // Aplica qualidade/compressão se solicitado
267
- if (quality) {
268
- const q = parseInt(quality);
269
- if (ext === 'jpeg' || ext === 'jpg')
270
- transformer.jpeg({ quality: q });
271
- if (ext === 'webp')
272
- transformer.webp({ quality: q });
273
- if (ext === 'avif')
274
- transformer.avif({ quality: q });
275
- if (ext === 'png')
276
- transformer.png({ quality: q });
277
- }
278
- buffer = await transformer.toBuffer();
279
- // Atualiza o tamanho para a decisão de inline/emit abaixo
280
- }
281
- }
282
- catch (e) {
283
- Console.warn(`Failed to optimize image ${path.basename(cleanId)}:`, e.message);
284
- // Falha silenciosa: usa o buffer original
285
- }
286
- }
287
- // ------------------------------------------
288
239
  const size = buffer.length;
289
240
  // Tratamento especial para SVG (inline SVG vs URL)
290
241
  if (type === 'svg') {
@@ -312,17 +263,18 @@ const smartAssetPlugin = (isProduction) => {
312
263
  }
313
264
  }
314
265
  // Para outros assets:
315
- // Se for pequeno (ou ficou pequeno após resize), Base64
266
+ // Se for pequeno, Base64 (reduz requests HTTP)
267
+ // Se for grande, Arquivo (reduz uso de RAM e tamanho do bundle JS)
268
+ // Essa lógica agora aplica para DEV e PROD. Base64 em Dev para arquivos grandes era o vilão da RAM.
316
269
  if (size < INLINE_LIMIT) {
317
270
  const base64 = buffer.toString('base64');
318
271
  buffer = null; // Libera memória do buffer bruto imediatamente
319
272
  return `export default "data:${type};base64,${base64}";`;
320
273
  }
321
274
  else {
322
- // Se ainda for grande, emite arquivo
323
275
  const referenceId = this.emitFile({
324
276
  type: 'asset',
325
- name: path.basename(cleanId), // O nome será hasheado pelo Rollup output options
277
+ name: path.basename(cleanId),
326
278
  source: buffer
327
279
  });
328
280
  buffer = null; // Libera memória
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vatts",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "itsmuzin",