Skip to content

Commit

Permalink
fix(nuxt): normalise rollup opts in island transform w/o nuxt (#26589)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Apr 3, 2024
1 parent 59b58b8 commit 2dc4505
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/nuxt/src/components/islandsTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MagicString from 'magic-string'
import { ELEMENT_NODE, parse, walk } from 'ultrahtml'
import { hash } from 'ohash'
import { resolvePath } from '@nuxt/kit'
import defu from 'defu'
import { isVue } from '../core/utils'

interface ServerOnlyComponentTransformPluginOptions {
Expand Down Expand Up @@ -146,7 +147,7 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran
* extract attributes from a node
*/
function extractAttributes (attributes: Record<string, string>, names: string[]) {
const extracted:Record<string, string> = {}
const extracted: Record<string, string> = {}
for (const name of names) {
if (name in attributes) {
extracted[name] = attributes[name]
Expand Down Expand Up @@ -182,15 +183,27 @@ export const componentsChunkPlugin = createUnplugin((options: ComponentChunkOpti
vite: {
async config (config) {
const components = options.getComponents()
config.build = config.build || {}
config.build.rollupOptions = config.build.rollupOptions || {}
config.build.rollupOptions.output = config.build.rollupOptions.output || {}
config.build.rollupOptions.input = config.build.rollupOptions.input || {}

config.build = defu(config.build, {
rollupOptions: {
input: {},
output: {}
}
})

const rollupOptions = config.build.rollupOptions!

if (typeof rollupOptions.input === 'string') {
rollupOptions.input = { entry: rollupOptions.input }
} else if (typeof rollupOptions.input === 'object' && Array.isArray(rollupOptions.input)) {
rollupOptions.input = rollupOptions.input.reduce<{ [key: string]: string }>((acc, input) => { acc[input] = input; return acc }, {})
}

// don't use 'strict', this would create another "facade" chunk for the entry file, causing the ssr styles to not detect everything
config.build.rollupOptions.preserveEntrySignatures = 'allow-extension'
rollupOptions.preserveEntrySignatures = 'allow-extension'
for (const component of components) {
if (component.mode === 'client' || component.mode === 'all') {
(config.build.rollupOptions.input as Record<string, string>)[component.pascalName] = await resolvePath(component.filePath)
rollupOptions.input![component.pascalName] = await resolvePath(component.filePath)
}
}
},
Expand Down

0 comments on commit 2dc4505

Please sign in to comment.