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

Library mode: ES Modules / es outputs not minified #6079

Closed
7 tasks done
oscarnewman opened this issue Dec 11, 2021 · 1 comment
Closed
7 tasks done

Library mode: ES Modules / es outputs not minified #6079

oscarnewman opened this issue Dec 11, 2021 · 1 comment

Comments

@oscarnewman
Copy link

Describe the bug

When setting up a new Vite project to build a package, all output formats appear to be minified except for the es / ES module output file.

In my testing, cjs, iife, and umd builds are all properly minified by default, bug es is not (when using build.minify, passing true, "esbuild", or "terser", or when not specifying build.minify`).

I've reproduced in a sample repo with a new Vite app using typescript and pnpm.

The following is the four files in the dist/ folder after running vite build.

image

Workaround:
It looks like using esbuild.minify = true as a config option works.

It's possible this is the intended behavior and I misunderstood the docs -- if so, feel free to close this!

Reproduction

https://github.com/oscarnewman/vite-minify-issue-reproduction

See build.log for the build log.

This was scaffolded with pnpm create vite with the vanilla TS setup, and the following steps:

  • Add an index.ts file to test minifying
  • Add the build configuration included below

I've reproduced on my machine here with the following vite.config.ts:

import { defineConfig } from "vite";

export default defineConfig({
    /**
     * Uncomment the following to make minification work for `es` outputs.
     */
    // esbuild: {
    //     minify: true,
    // },
    build: {
        minify: true,
        lib: {
            name: 'lib',
            entry: 'src/index.ts',
            formats: ['es', 'cjs' ,'iife', 'umd'],
        }
    }
})

System Info

System:
    OS: macOS 12.0.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 188.69 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /var/folders/c_/36b_bwk55pqd539xbk065m_00000gp/T/fnm_multishells/60927_1639202104485/bin/node
    Yarn: 1.22.15 - /var/folders/c_/36b_bwk55pqd539xbk065m_00000gp/T/fnm_multishells/60927_1639202104485/bin/yarn
    npm: 8.1.2 - /var/folders/c_/36b_bwk55pqd539xbk065m_00000gp/T/fnm_multishells/60927_1639202104485/bin/npm
  Browsers:
    Edge: 96.0.1054.53
    Firefox: 95.0
    Safari: 15.1
  npmPackages:
    vite: ^2.7.0 => 2.7.1

Used Package Manager

pnpm

Logs

2021-12-11T18:10:19.680Z vite:config bundled config file loaded in 12.84ms
2021-12-11T18:10:19.684Z vite:config using resolved config: {
  build: {
    target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
    polyfillModulePreload: true,
    outDir: '/Users/oscar/Documents/misc/minify-test/dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: false,
    cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
    sourcemap: false,
    rollupOptions: { input: '/Users/oscar/Documents/misc/minify-test/src/index.ts' },
    minify: 'esbuild',
    terserOptions: {},
    write: true,
    emptyOutDir: null,
    manifest: false,
    lib: { name: 'lib', entry: 'src/index.ts', formats: [Array] },
    ssr: false,
    ssrManifest: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    commonjsOptions: { include: [Array], extensions: [Array] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  },
  configFile: '/Users/oscar/Documents/misc/minify-test/vite.config.ts',
  configFileDependencies: [ 'vite.config.ts' ],
  inlineConfig: {
    root: undefined,
    base: undefined,
    mode: undefined,
    configFile: undefined,
    logLevel: undefined,
    clearScreen: undefined,
    build: {}
  },
  root: '/Users/oscar/Documents/misc/minify-test',
  base: '/',
  resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  publicDir: '/Users/oscar/Documents/misc/minify-test/public',
  cacheDir: '/Users/oscar/Documents/misc/minify-test/node_modules/.vite',
  command: 'build',
  mode: 'production',
  isProduction: true,
  plugins: [
    'alias',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-script-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm',
    'vite:worker',
    'vite:asset',
    'vite:define',
    'vite:css-post',
    'vite:watch-package-data',
    'vite:build-html',
    'commonjs',
    'vite:data-uri',
    'rollup-plugin-dynamic-import-variables',
    'vite:asset-import-meta-url',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:reporter',
    'vite:load-fallback'
  ],
  server: { fs: { strict: true, allow: [Array], deny: [Array] } },
  preview: {
    port: undefined,
    strictPort: undefined,
    host: undefined,
    https: undefined,
    open: undefined,
    proxy: undefined,
    cors: undefined
  },
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(0) { set: [Function (anonymous)] },
  createResolver: [Function: createResolver],
  optimizeDeps: {
    esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  }
}
vite v2.7.1 building for production...
transforming...
✓ 1 modules transformed.
rendering chunks...
dist/minify-test.es.js   0.07 KiB / gzip: 0.08 KiB
dist/minify-test.cjs.js   0.14 KiB / gzip: 0.14 KiB
dist/minify-test.iife.js   0.16 KiB / gzip: 0.15 KiB
dist/minify-test.umd.js   0.35 KiB / gzip: 0.24 KiB

Validations

@Niputi
Copy link
Contributor

Niputi commented Dec 11, 2021

duplicate of #5167

@Niputi Niputi closed this as completed Dec 11, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants