I have a library build using reactJS and vite https://github.com/gsharath/sample-for-st-lib , which I am using in another react project https://github.com/gsharath/sample-for-st . When I do npm install , it installs the minified version of the library, which seems good so far.
This is what I have in my sample-for-st-lib library:
export const Button = ()=>{
return(
<button>My Button</button>
)
}
This is my vite.config for my library
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path';
export default defineConfig({
build: {
lib: {
entry: {
components: path.resolve(__dirname, './src/components/index.js')
},
name: 'sample-for-st-lib',
},
rollupOptions: {
external: ['react','react-dom'],
},
emptyOutDir: true,
},
plugins: [react()],
});
I am referring this in my project using:
import { Button } from "sample-for-st-lib/components"
function App() {
return (
<>
<Button />
Test library
</>
)
}
Now while doing dev work and to debug issues, I am using npm link to create link between the library and project, so that
- I need not publish the package every time
- Assumed, I can open developer tools and find out the component from my-new-package and debug it in developer tools ( chrome ). Adding a screenshot of dev tools where I can find the component that I am looking for.
I looked at sourcemap option in vite.config which doesn't seem to be helping here.
I understand that since I am using this as a library, we need to rely on storybook to see how the components looks during dev mode or write something in library as a wrapper which helps me to debug it there, but I am looking to find out a way to debug the components from where my library is used. Did someone encounter this before and have something to guide me.
Any help is highly appreciated. Sorry for the not-so-good-formatting

In order to help debug during development with your current workflow, there are two key things to change from the github repos you linked to:
npm uninstall sample-for-st-libwithinsample-for-st(so you can properly link them withnpm)sourcemapto the vite build insample-for-st-lib, ideally behind some env varFrom fresh checkouts, starting with
sample-for-st-lib:npm installsourcemapto your vite build ('inline')npm run buildnpm linkNow a fresh checkout of
sample-for-st:npm installnpm uninstall sample-for-st-libnpm link sample-for-st-libnpm run devFrom here you can go back to
sample-for-st-libmake changes toButtonand then, here is the key, remember to runnpm run build, so the changes can be picked up by the vite dev server running forsample-for-st.Intentionally cause an error in
Buttonby calling a function that doesn't exist, rebuild, and you should be able to see the source code for Button in your dev tools.