-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Open
Open
Copy link
Description
Clear and concise description of the problem
As a developer using Vite I want to able to conditional set vite configurations based on the used library mode format.
Currently this is not possible.
Suggested solution
I thought of something like this, but I'm not sure if this possible because the current env parameter is set with properties before the viteconfig is being created. So it will maybe impossible to know the formats.
import path from "path";
import { defineConfig } from "vite";
export default defineConfig((env) => ({
build: {
lib: {
entry: path.resolve(process.cwd(), 'lib/main.ts'),
name: 'MyLib',
formats: ['umd', 'cjs', 'es'],
fileName: (format) => `${format}/my-lib.js`
},
rollupOptions: {
output: {
preserveModules: env.libFormat === 'es'
}
}
},
}))Alternative
Alternatively I thought of something like this. By this you can configure multiple configs for each format. This maybe easier to adapt but can be less readable.
import path from "path";
import { defineConfig } from "vite";
export default defineConfig({
build: {
lib: {
entry: path.resolve(process.cwd(), 'lib/main.ts'),
name: 'MyLib',
formats: ['umd', 'cjs', 'es'],
fileName: (format) => `${format}/my-lib.js`,
// Build config only for "LibraryMode"
buildConfig: {
minify: false
},
// or: Conditional config for each format
buildConfig: (format) => ({
rollupOptions: {
output: {
preserveModules: format === 'es'
}
}
})
},
},
})Additional context
Maybe duplicate of #6954
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Reactions are currently unavailable