Skip to content

Commit

Permalink
fix: normalize #build windows path for dev and prerender presets (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Apr 11, 2022
1 parent c618f2d commit ec5db11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/presets/nitro-dev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToFileURL } from 'url'
import { isWindows } from 'std-env'
import { defineNitroPreset } from '../preset'

export const nitroDev = defineNitroPreset({
Expand All @@ -8,5 +10,13 @@ export const nitroDev = defineNitroPreset({
},
externals: { trace: false },
inlineDynamicImports: true, // externals plugin limitation
sourceMap: true
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
}
}
}
})
12 changes: 11 additions & 1 deletion src/presets/nitro-prerender.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToFileURL } from 'url'
import { isWindows } from 'std-env'
import { defineNitroPreset } from '../preset'

export const nitroPrerender = defineNitroPreset({
Expand All @@ -6,5 +8,13 @@ export const nitroPrerender = defineNitroPreset({
output: {
serverDir: '{{ buildDir }}/prerender'
},
externals: { trace: false }
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
}
}
}
})
7 changes: 1 addition & 6 deletions src/rollup/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { pathToFileURL } from 'url'
import { dirname, join, relative, resolve } from 'pathe'
import type { InputOptions, OutputOptions } from 'rollup'
import defu from 'defu'
Expand All @@ -12,7 +11,6 @@ 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 @@ -226,10 +224,7 @@ export const plugins = [
rollupConfig.plugins.push(alias({
entries: resolveAliases({
'#nitro': runtimeDir,
// Windows dynamic imports should be file:// url
'#build': nitro.options.dev && isWindows
? pathToFileURL(nitro.options.buildDir).href
: nitro.options.buildDir,
'#build': nitro.options.buildDir,
'~': nitro.options.srcDir,
'@/': nitro.options.srcDir,
'~~': nitro.options.rootDir,
Expand Down

0 comments on commit ec5db11

Please sign in to comment.