-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Support reading pre existing external source maps #11743
Comments
@segevfiner Do you have a vite.config example how to support external source maps with vite and that rollup plugin? |
I need this feature as well as I have a mono-repo with the following structure:
where
import { defineConfig } from 'vite';
import sourcemaps from 'rollup-plugin-sourcemaps';
export default defineConfig({
build: {
rollupOptions: {
plugins: [sourcemaps()],
output: {
sourcemap: true,
},
},
lib: {
entry: 'src/index.ts',
name: 'LibraryA',
fileName: 'lib-a',
},
},
}); |
It would be really awesome to have this feature added to Vite! @mrshannon, thanks for sharing your example! It's been super helpful in tackling the issue with external source maps. import { defineConfig } from 'vite';
import sourcemaps from 'rollup-plugin-sourcemaps';
export default defineConfig({
build: {
rollupOptions: {
plugins: [sourcemaps()],
},
sourcemap: true, // <----------
lib: {
entry: 'src/index.ts',
name: 'LibraryA',
fileName: 'lib-a',
},
},
}); I found out that it works better, at least in my project. |
Hey there, We are experiencing the same problem. We split our projtects in 2 parts. First part is, we are building a framework which is then build as library. When running the dev server, all sourcemaps seem to work. But when building the application and deploying it on a server, only the client sourcemaps are working and not the framework sourcemaps. Is there a way to bundle external library sourcemaps somehow? I have tried quite a lot already but it all didn't seem to work. EDIT |
I thought that Vite doesn't support sourcemaps via rollup anymore. At least according to this warning message:
I'm currently running into a similar issue because vite-plugin-singlefile makes that some of the sourcemaps are not working even with build.sourcemap = 'inline'. Has anyone found another way to workaround this? I'm looking for a similar solution to rollup-plugin-sourcemaps where it transpiles, sourcemaps it, and then build it into a singlefile... |
Can you share your vite.config. in my case sourcemaps don't work even for the dev server |
There's a few layers to this. First, vite can create sourcemaps, though it does not read existing sourcemaps from external dependencies. To enable sourcemaps, you have to enable it with the To enable sourcemaps for code in the primary project, change your vite config to add the import {defineConfig} from 'vite';
export default defineConfig({
build: {
sourcemap: true,
},
}); Second, the This is what this issue was created to request. To re-export sourcemaps for package dependencies, install the plugin and update your config: import {defineConfig} from 'vite';
import sourceMaps from 'rollup-plugin-sourcemaps';
export default defineConfig({
build: {
sourcemap: true,
rollupOptions: {
plugins: [sourceMaps()],
},
},
}); Lastly, there are two other settings that will ignore sourcemaps in the chrome devtools if you have enabled the feature. By default, this is anything in node_modules folder so if your dependency is in a monorepo, this should not affect you. For the dev server, this is |
@lachieh |
When using the rollup-plugin-sourcemaps, my |
Yes, we encountered the same issue. You can check for the Then, you can conditionally add I understand this isn't a perfect solution, but it worked for us. |
Description
I found myself having to use https://github.com/maxdavidson/rollup-plugin-sourcemaps quite often so that Vite libraries in our monorepo have proper source maps, as Rollup doesn't load external source maps by default. Considering how common this feels to be for me, it might make sense to add this as builtin functionality in Vite, especially since that plugin doesn't seem to be receiving much maintenance and has a few open issues ATM.
Suggested solution
Vite will support reading in and merging external pre existing source maps, so that you are able to debug library code that has source maps.
Alternative
Keep using the plugin, considering to fork it to fix some issues.
Additional context
Basically, imagine a Vite library project and multiple Vite apps that use it and you want to be able to debug the library code with proper source maps in the apps, both during development and in production.
Validations
The text was updated successfully, but these errors were encountered: