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

Option to rename _virtual folder #4437

Closed
jacksteamdev opened this issue Mar 10, 2022 · 6 comments
Closed

Option to rename _virtual folder #4437

jacksteamdev opened this issue Mar 10, 2022 · 6 comments

Comments

@jacksteamdev
Copy link
Contributor

Feature Use Case

I need to preserve the default export in a plugin I'm building for developing Chrome Extensions; some code I don't control uses default export. When I use preserveModules, virtual files get put in the folder _virtual.

This is all fine, except that _virtual is an illegal filename for my use case; files and folders in Chrome Extensions cannot start with _.

Feature Proposal

I understand there's some difficulty in using the strict return value of entryFileNames, but it would be useful to be able to change the name of the virtual folder.

I've tried renaming everything in the bundle manually, but my plugin relies heavily on this.getFileName, which doesn't reflect changes to the bundle. Maybe this is a bug or I'm doing something wrong, but it would be great to be able to configure _virtual to something else.

path = `_virtual/${fileName}`;

As far as I'm concerned, it doesn't have to be a dynamic option, a static string would be enough.

@lukastaegert
Copy link
Member

Why do you rely on preserveModules? It is almost always a suboptimal choice. It is far better to explicitly list the entry points you want to have exposed in the input option, then Rollup will automatically take care of the rest and there will be no _virtual (also, I want to avoid feature creep with options that are hardly ever used).

@nikitakot
Copy link

@jacksteamdev I have the exact same issue. How did you solve it in the end? I want to keep es modules in my background service worker (because I need to obfuscate certain modules but not all of them). My background sw also imports a node module which is exported as a commonjs and it creates _virtual folder in the dist.

@lukastaegert
Copy link
Member

You should be able to use output.sanitizeFileName with a function to fix up the name.

@nikitakot
Copy link

You should be able to use output.sanitizeFileName with a function to fix up the name.

@lukastaegert is there an export for the default sanitizeFileName sanitize function? Or a way how to keep the default sanitization and extend it with custom logic?

@nikitakot
Copy link

nevermind, I got what @lukastaegert meant with It is far better to explicitly list the entry points you want to have exposed in the input option. I programmatically specify all files which background sw includes and the build output looks almost like I need it. The only thing - can I somehow preserve modules relative path? So they don't all appear in the dist root but in the folders they were in the source code folder.

@lukastaegert
Copy link
Member

You can do that if you provide an object for input (that may even be generated programmatically) that provides names with path fragments. I.e. something like

input: {
  'foo/bar': 'src/foo/bar.js',
  'baz': 'src/baz.js'
}

should give you what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants