Skip to content
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

Temporary sourcemaps support #12828

Closed
4 tasks done
ikenfin opened this issue Apr 11, 2023 · 6 comments
Closed
4 tasks done

Temporary sourcemaps support #12828

ikenfin opened this issue Apr 11, 2023 · 6 comments

Comments

@ikenfin
Copy link

ikenfin commented Apr 11, 2023

Description

As a developer of vite-plugin-sentry i've seen many feature requests from users to add option to delete sourcemaps after they become uploaded to external service (Sentry in my case). issue

While there are exist some workarounds, i think better solution would control sourcemaps generation and cleaning processes at Vite level.

Suggested solution

I think it would be perfect to have some option to generate sourcemaps temporary.

// Example of config:
build: {
  sourcemap: 'hidden',
  sourcemapTemporary: true // by default false 
}

When sourcemapTemporary is false - there are no any changes in Vite behavior.
When sourcemapTemporary is true - Vite runs as always. At the end of bundling process, Vite removes generated sourcemaps (option is ignored if sourcemap was false).

Alternative

For now there are several possible workarounds (from better to worst):

  1. Using CI like Jenkins to skip sourcemap files
  2. Manual removing by using rimraf or similar tool (vite build && rimraf dist/**/*.map)
  3. Providing plugin level option to remove sourcemaps (most sourcemap uploaders implemented in this manner at the moment).

Additional context

No response

Validations

@bluwy
Copy link
Member

bluwy commented Apr 11, 2023

3. Providing plugin level option to remove sourcemaps (most sourcemap uploaders implemented in this manner at the moment).

With the generateBundle hook, you should be able to do that? e.g.

generateBundle(_, bundle) {
  for (const file in bundle) {
    if (file.endsWith('.map')) {
      delete bundle[file]
    }
  }
}

@ikenfin
Copy link
Author

ikenfin commented Apr 12, 2023

@bluwy Thanks, this looks better than manual removing, but is'nt that solution strips out sourcemaps before next plugin run?

My idea was to provide generated sourcemaps to each plugin, no matter in which order it was added, and delete them at bundling finish.

@bluwy
Copy link
Member

bluwy commented Apr 12, 2023

You can use enforce: 'post' or the order: "post" so that your plugin runs near the end. So I don't think it would be an issue.

@ikenfin
Copy link
Author

ikenfin commented Apr 13, 2023

So I don't think it would be an issue.

But it is - multiple plugins can use same technique with enforce and order usage. My initial request was about providing some safe way to use sourcemaps in multiple plugins while building, without worrying of their ordering or internal implementation. Like adding && rimraf but using more native way

@bluwy
Copy link
Member

bluwy commented Apr 13, 2023

We won't add a new option if it can already be achieved by a plugin. There are more plugins that do a lot more similar stuff, and it had worked so far, so it's not an issue.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2023
@ikenfin
Copy link
Author

ikenfin commented Apr 13, 2023

Yes, this can be achieved at plugin level, but this is requiring from user to strongly follow plugins order and enable sourcemap deletion only for last one. Anyway i got you, seems like better solution for now is to recommend users to use separate sourcemap remover plugin

@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants