-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Export complete files instead of having shared ones #85
Comments
Interesting FR. Although I haven't needed it myself, I can definitely see it being useful. FYI seems like it was requested in Rollup as well but it's been open for a long time: The workaround shared there is to create multiple builds, but to avoid the duplicated processing overhead, I'm curious if we can make a plugin that duplicates every shared module with a unique ID right before the bundling step so Rollup thinks none of the dependencies are shared. Feel free to play around with implementation ideas and open a PR. |
Hmm... It looks like the plugin idea was already mentioned in the issue here. To prevent collisions, which could be possible (though rare) in the solution linked above, something could probably be done like this: import path from 'path';
let nextId = -1;
const disableChunks = (targets = []) => {
/** @type{import('rollup').Plugin} */
const plugin = {
name: 'disable-chunks',
async resolveId(source, importer, options) {
const resolved = await this.resolve(source, importer, options);
if(resolved && targets.some(file => resolved.id.includes(file))) {
++nextId;
return `${resolved.id}?unique=${nextId.toString(16)}`;
}
},
load(id) {
const regex = /(\?unique=[a-zA-Z0-9]*)$/;
if(regex.test(id)) {
return this.load({id: id.replace(regex, '')});
}
},
generateBundle(options, bundle) {
const nonEntryChunks = Object.values(bundle).filter(({isEntry}) => !isEntry);
if(nonEntryChunks.length > 0) {
const moduleIds = new Set(
nonEntryChunks.map(({moduleIds}) => moduleIds)
.flat()
.map(absPath => path.relative('.', absPath))
);
throw new Error(`Found non-entry chunks: ${Array.from(moduleIds).join(', ')}`);
}
}
};
return plugin;
}; Then, if some option (e.g. command line or other) is included in pkgroll with the files to exclude as chunks, it can be included as an option in the rollup configs (get-rollup-configs.ts?) to disable chunk generation for specific files similar to this: // rollup.config.mjs
export default defineConfig([
{
input: ['src/index1.ts', 'src/index2.ts'],
output: {
dir: 'dist'
},
plugins: [
disableChunks(['src/shared.ts']),
typescript({module: 'ESNext'})
]
}
]); I am finding it a bit hard to directly implement this in get-rollup-configs.ts or where this would be required. Any advice/guidance would be much appreciated, @privatenumber. 😊 |
Oh good catch! I missed that. For configuration, I'm thinking we can adopt a naming convention similar to The custom plugin should be added in here: And added in this array if there's an entry point with Instead of the incremental |
@privatenumber Hmm... Trying to work through this but having trouble figuring out how to get the |
You can accept it as a parameter in |
Feature request
Basically, let us say my project contains the following typescript files:
a.ts and b.ts both depend on c.ts.
If my package.json has this:
It will export one a.js file, which includes the contents of the c.ts compiled to JS.
If my package.json has this:
It will export the following files:
a.js and b.js will both import from c-[arbitrary-string-of-characters].js.
Is there a way to simply export only a.js and b.js with both having the full contents of c.js within them?
Motivations
I came across this when trying to create multiple full exported JS files using pkgroll.
Alternatives
No response
Additional context
No response
Bugs are expected to be fixed by those affected by it
Compensating engineering work financially will speed up resolution
The text was updated successfully, but these errors were encountered: