good evening your article fell from the sky, I would like to share an improvement
import react from '@vitejs/plugin-react'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { defineConfig, UserConfigExport } from 'vite'; import dts from 'vite-plugin-dts'; const App = async (): Promise<UserConfigExport> => { var name: string = 'replaceme'; const data: string = await readFile(path.join(__dirname, 'src', 'lib', 'index.tsx'), { encoding: 'utf-8' }) const s = data.split('\n') for (let x of s.reverse()) if (x.includes('export default')) name = x.replace('export default ', '').replace(" ", "") return defineConfig({ plugins: [ react(), dts({ insertTypesEntry: true, }), ], build: { lib: { entry: path.resolve(__dirname, 'src/lib/index.tsx'), name, formats: ['es', 'umd'], fileName: (format) => `lib.${format}.js`, }, rollupOptions: { external: ['react', 'react-dom', 'styled-components'], output: { globals: { react: 'React', 'react-dom': 'ReactDOM', 'styled-components': 'styled', }, }, }, }, }); } export default App
This improvement takes the name of the component that we are exporting, so that it is dynamic to obtain the name to import it into our projects
and it works great!
I took the liberty of exporting our code as lib by default, so I didn't have to keep renaming the files.
Nice improvements! Thanks :)
maybe a repo link? i tried your solution but Im not sure how to, or what it suppose to do?
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
good evening your article fell from the sky, I would like to share an improvement
This improvement takes the name of the component that we are exporting, so that it is dynamic to obtain the name to import it into our projects
and it works great!
I took the liberty of exporting our code as lib by default, so I didn't have to keep renaming the files.
Nice improvements! Thanks :)
maybe a repo link? i tried your solution but Im not sure how to, or what it suppose to do?