Skip to content

Commit

Permalink
fix: module builder chunk path patch
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 10, 2024
1 parent 14a87b9 commit 87199a1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/devtools/build.config.ts
@@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
Expand All @@ -22,4 +23,32 @@ export default defineBuildConfig({
rollup: {
inlineDependencies: true,
},
hooks: {
// Patch @nuxt/module-builder@0.6.0 not adding .mjs extension for runtime files
// https://github.com/nuxt/module-builder/issues/261
'rollup:options': (_, options) => {
options.plugins ||= []
if (!Array.isArray(options.plugins))
options.plugins = [options.plugins]

const runtimeDir = fileURLToPath(new URL('./src/runtime', import.meta.url))
options.plugins.unshift({
name: 'unbuild:runtime-build:patch',
async resolveId(id, importter) {
if (!id.includes('runtime'))
return
const resolved = await this.resolve(id, importter, { skipSelf: true })
if (resolved?.id.startsWith(runtimeDir)) {
let id = resolved.id
if (!id.endsWith('.mjs'))
id += '.mjs'
return {
external: true,
id,
}
}
},
})
},
},
})

0 comments on commit 87199a1

Please sign in to comment.