-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
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.
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.tsfile to test minifying - Add the
buildconfiguration 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.1Used 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 KiBValidations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
