Replies: 1 comment
-
|
Vite (and Rollup underneath) resolves package entry points using the For {
"main": "dist/react-google-maps-api.cjs.min.js",
"module": "dist/esm.js"
}Vite prefers This is actually the correct behavior for a library build. Here is why:
So the unminified resolution is intentional. To get a small output, rely on your own build's minification: export default defineConfig({
build: {
lib: { entry: "src/index.ts", formats: ["es"] },
minify: "terser", // or "esbuild" (default)
},
})If you genuinely need to force Vite to resolve a specific file from a dependency, use export default defineConfig({
resolve: {
alias: {
"@react-google-maps/api": "@react-google-maps/api/dist/react-google-maps-api.cjs.min.js",
},
},
})But this trades tree shaking for a smaller pre-minified input, which is rarely a net win. The better path: let Vite resolve the ESM source, tree-shake it, and minify the final output in one pass. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building an app in library mode. My config looks like this
I'll use https://github.com/JustFly1984/react-google-maps-api in this example. It provides several minified and unminified files:
Vite bundles unminifed file
esm.jsIs it possible to configure to use
.min.jsfiles instead?Beta Was this translation helpful? Give feedback.
All reactions