Skip to content

Commit

Permalink
Allow rollupOptions set by other plugins to be respected
Browse files Browse the repository at this point in the history
Storybook (builder-vite) adds an `iframe.html` entry into the `rollupOptions` when building a static build. I found that `vite-plugin-ruby` is overriding these options meaning that the Storybook build fails.

Here I am allowing any existing rollup options + inputs to be spread into the config before the plugin returns it.
  • Loading branch information
blake-simpson committed Aug 7, 2024
1 parent ebe50b8 commit dbb74a6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion vite-plugin-ruby/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,26 @@ const debug = createDebugger('vite-plugin-ruby:config')
function config (userConfig: UserConfig, env: ConfigEnv): UserConfig {
const config = loadConfiguration(env.mode, projectRoot, userConfig)
const { assetsDir, base, outDir, server, root, entrypoints, ssrBuild } = config
const existingRollupOptions = userConfig.build?.rollupOptions || {};

const isLocal = config.mode === 'development' || config.mode === 'test'

const buildRollupInputs = () => {
const existingInputs = userConfig.build?.rollupOptions?.input || {};

if (typeof existingInputs === 'string') {
return {
[existingInputs]: existingInputs,
...Object.fromEntries(filterEntrypointsForRollup(entrypoints)),
};
} else {
return {
...existingInputs,
...Object.fromEntries(filterEntrypointsForRollup(entrypoints)),
};
}
}

const build = {
emptyOutDir: userConfig.build?.emptyOutDir ?? (ssrBuild || isLocal),
sourcemap: !isLocal,
Expand All @@ -45,7 +62,7 @@ function config (userConfig: UserConfig, env: ConfigEnv): UserConfig {
manifest: !ssrBuild,
outDir,
rollupOptions: {
input: Object.fromEntries(filterEntrypointsForRollup(entrypoints)),
input: buildRollupInputs(),
output: {
...outputOptions(assetsDir, ssrBuild),
...userConfig.build?.rollupOptions?.output,
Expand Down

0 comments on commit dbb74a6

Please sign in to comment.