nonzzz / vite-plugin-compression

vite plugin. compress your bundle file.
MIT License
171 stars 10 forks source link

Compression is performed at the stage `configResolved` #63

Closed ben-lau closed 2 months ago

ben-lau commented 2 months ago

I use prerender plugin in my project, it will launch a browser with my compile product at the stage generateBundle, but this plugin completes the compression before that. Cause my html inside gz is the origin template, not the prerendered one, but outside the gz file, there is the prerendered html file. Can it be solved? Thank you.

nonzzz commented 2 months ago

What's prerender plugin? Do you mean Pre-rendering? Can you share your vite's conf?

ben-lau commented 2 months ago

yep, the prerender plugin use puppeteer to render html.

import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import compression from 'vite-plugin-compression2';
import prerender from '@prerenderer/rollup-plugin';
import basicSsl from '@vitejs/plugin-basic-ssl';
import { analyzer } from 'vite-bundle-analyzer';

export default defineConfig({
  esbuild: { drop: ['console'] },
  plugins: [
    vue(),
    vueJsx(),
    prerender({
      routes: ['/'],
      renderer: '@prerenderer/renderer-puppeteer',
      rendererOptions: {
        renderAfterDocumentEvent: 'custom-render-trigger',
        headless: false,
        injectProperty: '__IS_PRERENDERING__',
        inject: '__IS_PRERENDERING__',
      },
    }),
    basicSsl(),
    compression(),
    // analyzer(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});
nonzzz commented 2 months ago

@ben-lau v1.2.0 released. Try it.

ben-lau commented 2 months ago

Perfect , it's working great!