I am trying to publish a React ponent as an npm module using the library mode of Vite. But even though my entry file does not import or use the image vite.svg
it is copied to the dist folder.
vite.config.js:
export default defineConfig({
plugins: [react()],
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/index.jsx'),
name: 'MyLib',
// the proper extensions will be added
fileName: 'my-lib',
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ['react', 'react-dom'],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
},
},
},
})
src/index.jsx:
import React from 'react';
export function Button(props) {
return <button {...props} />;
}
dist