Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite 2.6+ produces 50% larger output file for ESM #8099

Closed
7 tasks done
rburgst opened this issue May 10, 2022 · 2 comments · Fixed by #8110
Closed
7 tasks done

vite 2.6+ produces 50% larger output file for ESM #8099

rburgst opened this issue May 10, 2022 · 2 comments · Fixed by #8110

Comments

@rburgst
Copy link

rburgst commented May 10, 2022

Describe the bug

Vite versions >= 2.6 produce approx 50% larger bundle sizes for our project.

With vite 2.5.10:

yarn build
yarn run v1.22.18
$ tsc && vite build
vite v2.5.10 building for production...
transforming (1) src/index.tsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
✓ 11 modules transformed.
dist/vite-bundle-size-problem.es.js   2147.03 KiB / brotli: skipped (large chunk)
dist/vite-bundle-size-problem.umd.js   2147.39 KiB / brotli: skipped (large chunk)
✨  Done in 14.95s.

With vite 2.9.8

vite v2.9.8 building for production...
transforming (1) src/index.tsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
✓ 11 modules transformed.
dist/vite-bundle-size-problem.es.js   3211.96 KiB / gzip: 737.04 KiB

Note that

a) the build does not complete (at least not within 5 minutes or so).
b) the ES output file is now 3211.96 KiB compared to 2147.03 KiB

Repro steps

  1. run yarn install
  2. run yarn build (by default we use vite 2.9.8) note that the build does not terminate and the output file is 3MB
  3. change package.json and replace "vite": "~2.9.8" with "vite": "~2.5.10"
  4. run yarn install && yarn build and observe the file size is now only 2 MB

Reproduction

https://github.com/rburgst/vite-bundle-size-problem

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 522.84 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.volta/tools/image/node/16.13.1/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.1.2 - ~/.volta/tools/image/node/16.13.1/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 100.1.37.111
    Chrome: 101.0.4951.54
    Firefox: 100.0
    Safari: 15.4
  npmPackages:
    vite: ~2.9.8 => 2.9.8

Used Package Manager

yarn

Logs

tsc && vite build --debug
  vite:config bundled config file loaded in 68.77ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'alias',
  vite:config     'vite:preact-jsx',
  vite:config     'preact:devtools',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'preact:config',
  vite:config     'prefresh',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:watch-package-data',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: './dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: false,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: {
  vite:config       entry: '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem/src/index.ts',
  vite:config       name: 'vite-bm-video'
  vite:config     },
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   optimizeDeps: {
  vite:config     include: [ 'preact/jsx-runtime' ],
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   resolve: {
  vite:config     dedupe: undefined,
  vite:config     alias: [ [Object], [Object], [Object], [Object], [Object] ]
  vite:config   },
  vite:config   configFile: '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem/vite.config.ts',
  vite:config   configFileDependencies: [
  vite:config     '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem/vite.config.ts'
  vite:config   ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem',
  vite:config   base: '/',
  vite:config   publicDir: '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem/public',
  vite:config   cacheDir: '/Users/Rainer.Burgstaller/git/redbull/vite-size-bug/vite-bundle-size-problem/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isWorker: false,
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +5ms
vite v2.9.8 building for production...
transforming (1) src/index.tsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
✓ 11 modules transformed.
dist/vite-bundle-size-problem.es.js   3211.96 KiB / gzip: 737.04 KiB

Validations

@sapphi-red
Copy link
Member

sapphi-red commented May 11, 2022

Firstly larger output is because the lib mode es output is not minified after 2.6 by intention (06d86e4). So this is not a bug.

Secondly, the build not ending seems like a bug. As far as I investigated, it does not happen with 2.8.6 but it happens with 2.9.8.

@sapphi-red
Copy link
Member

sapphi-red commented May 11, 2022

It does not happen with 2.9.6 and it happens with 2.9.7. Maybe #7948 is affecting this.

I confirmed #7948 is affecting this.

@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants