-
Notifications
You must be signed in to change notification settings - Fork 1
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
Plugin does not respect user's build.lib.formats
option.
#2
Comments
Yes, you’re right, the plugin forces ESM. It is because the plugin actually does two things: one, it preserves the modules in the output folder, and two, it allows you to copy assets into the output folder instead of inlining them. For example, given the following configuration: export default {
build: {
lib: {
entry: // ...
}
},
plugins: [
noBundlePlugin({
copy: ‘**/*.png’
})
]
} … and a file like this: import imgUrl from './img.png'
document.getElementById('hero-img').src = imgUrl This will result in the I guess there is no harm in removing the forced format to allow for other module systems as long as the caveats are documented. I can see why you might not need that particular functionality. May I know what your use case is with commonjs? |
I have removed the forced format in the latest release (2.0.1), so you should be able to use commonjs now 🙂 |
Thanks! An example use-case of mine would be a package published to NPM where bundling isn't necessary. While I write in TypeScript, I still prefer to publish as CommonJS as this is the easiest way for both ESM and CJS consumers of the package to use it, at least until the ESM ecosystem becomes more mature. I know Vite / Rollup aren't technically meant for this, but Vite's speed and tooling ecosystem (Vitest, for example) are fantastic, so I've been trying to develop a purely Vite-based toolchain for developing NPM packages. |
I suppose this implies that having multiple |
Interesting problem 🤔 I don't do anything specifically to prevent multiple formats, but I reckon it could have something to do with the I would like to look more into this, perhaps you could describe your use case so that I can find the right solution? 🙂 |
Yes, I can get to a working build by using My end goal was a dual build with export default defineConfig({
build: {
lib: {
formats: ['cjs', 'es'],
entry: ['src/index.ts'],
},
},
plugins: [
nobundle({
fileNames: '[name].[format]'
}),
],
}) For now, I've opted to simply use a native vite build in library mode by clearly specifying each |
Provided a configuration such as:
The output directory will contain files in ESM format. I believe this is happening due to this line, which when commented-out, causes Vite to respect the
formats
option provided by the user.The text was updated successfully, but these errors were encountered: