Skip to content

Commit

Permalink
fix: always apply #build windows fix when externals.trace is disa…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
pi0 committed Apr 11, 2022
1 parent e78f598 commit 1ec2ee4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/presets/nitro-dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { pathToFileURL } from 'url'
import { isWindows } from 'std-env'
import { defineNitroPreset } from '../preset'

export const nitroDev = defineNitroPreset({
Expand All @@ -10,13 +8,5 @@ export const nitroDev = defineNitroPreset({
},
externals: { trace: false },
inlineDynamicImports: true, // externals plugin limitation
sourceMap: true,
hooks: {
'nitro:rollup:before' (nitro) {
if (isWindows) {
// Windows dynamic imports should be file:// url
nitro.options.alias['#build'] = pathToFileURL(nitro.options.buildDir).href
}
}
}
sourceMap: true
})
12 changes: 1 addition & 11 deletions src/presets/nitro-prerender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { pathToFileURL } from 'url'
import { isWindows } from 'std-env'
import { defineNitroPreset } from '../preset'

export const nitroPrerender = defineNitroPreset({
Expand All @@ -8,13 +6,5 @@ export const nitroPrerender = defineNitroPreset({
output: {
serverDir: '{{ buildDir }}/prerender'
},
externals: { trace: false },
hooks: {
'nitro:rollup:before' (nitro) {
if (isWindows) {
// Windows dynamic imports should be file:// url
nitro.options.alias['#build'] = pathToFileURL(nitro.options.buildDir).href
}
}
}
externals: { trace: false }
})
9 changes: 8 additions & 1 deletion src/rollup/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathToFileURL } from 'url'
import { dirname, join, relative, resolve } from 'pathe'
import type { InputOptions, OutputOptions } from 'rollup'
import defu from 'defu'
Expand All @@ -11,6 +12,7 @@ import replace from '@rollup/plugin-replace'
import virtual from '@rollup/plugin-virtual'
import wasmPlugin from '@rollup/plugin-wasm'
import inject from '@rollup/plugin-inject'
import { isWindows } from 'std-env'
import { visualizer } from 'rollup-plugin-visualizer'
import * as unenv from 'unenv'
import type { Preset } from 'unenv'
Expand Down Expand Up @@ -221,10 +223,15 @@ export const plugins = [
}))

// https://github.com/rollup/plugins/tree/master/packages/alias
let buildDir = nitro.options.buildDir
// Windows (native) dynamic imports should be file:// urr
if (isWindows && (nitro.options.externals.trace === false)) {
buildDir = pathToFileURL(buildDir).href
}
rollupConfig.plugins.push(alias({
entries: resolveAliases({
'#nitro': runtimeDir,
'#build': nitro.options.buildDir,
'#build': buildDir,
'~': nitro.options.srcDir,
'@/': nitro.options.srcDir,
'~~': nitro.options.rootDir,
Expand Down

0 comments on commit 1ec2ee4

Please sign in to comment.