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

Add rollup's entryFileNames option #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sceniclife
Copy link

This adds this ability to specify rollup's entryFileNames configuration for the plugin.

Sometimes I want my output to have a different name than my spaEntryPoints.
Example: spaEntryPoints is "src/spa.tsx" but I would like my output to be src/index.tsx.

Adding support to output.entryFileNames
Add entryFileNames parameter to SingleSpaMifePluginOptions
@webJose
Copy link
Contributor

webJose commented Jul 31, 2024

Hello, @sceniclife. Thank you for your interest in the project and your pull request.

This plug-in sets entryFileNames because the resulting entry point file name is used in the CSS-injecting algorithm. Specifically, the filename (minus the extension) is used to key a dictionary of CSS filenames. This key must be specified by the developer when calling cssLifecycleFactory. If people is allowed to freely set entryFileNames, it complicates the user experience.

Is this a problem for a particular scenario that you are trying to cover?

@sceniclife
Copy link
Author

Hello @webJose ,

Yes, I see in the example

// IMPORTANT:  Because the file is named spa.tsx, the string 'spa'
// must be passed to the call to cssLifecycleFactory.
const cssLc = cssLifecycleFactory('spa', /* optional factory options */);

The default for spaEntryPoints is src/spa.ts , which would result in using spa for cssLifecycleFactory. If we changed from the default, the entryFileNames is [name].js, which is still valid.

In an example, I wanted the built spa to be in file index.js so that a root app can import as index.js. (say I can't change this). I can only change spaEntryPoints. If my application already has an index.ts(x), I'd have to rename that existing file in my app to something else.


With the PR above, I can specify spaEntryPoints to be whatever or leave it as default. Then I can set entryFileNames if needed and change the argument for cssLifecycleFactory to be the file from the build.

Lmk if there is another way to solve this

@webJose
Copy link
Contributor

webJose commented Aug 6, 2024

Hello, @sceniclife.

If you want the resulting file name to be index.js, can't you just rename the source file to index.ts?

export default defineConfig({
    plugins:[vitePluginSingleSpa({
        spaEntryPoints: ['src/index.ts']
    })],
    ...
});

The above Vite configuration will produce the bundle file index.js. Just use 'index' in your call to cssLifecycleFactory. Wouldn't this cover your need?

UPDATE: Sorry, forgot the "existing" thing: Just export from another folder:

export default defineConfig({
    plugins:[vitePluginSingleSpa({
        spaEntryPoints: ['src/spa/index.ts']
    })],
    ...
});

The above should work, right?

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

Successfully merging this pull request may close these issues.

2 participants