mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fixes for dev and static target
This commit is contained in:
parent
f638a44568
commit
6080927c16
@ -41,6 +41,7 @@ export interface SigmaContext {
|
||||
staticDir: string
|
||||
routerBase: string
|
||||
publicPath: string
|
||||
isStatic: boolean
|
||||
fullStatic: boolean
|
||||
staticAssets: any
|
||||
}
|
||||
@ -85,7 +86,8 @@ export function getsigmaContext (nuxtOptions: NuxtOptions, input: SigmaInput): S
|
||||
staticDir: nuxtOptions.dir.static,
|
||||
routerBase: nuxtOptions.router.base,
|
||||
publicPath: nuxtOptions.build.publicPath,
|
||||
fullStatic: nuxtOptions.preset === 'static' && !nuxtOptions._legacyGenerate,
|
||||
isStatic: nuxtOptions.target === 'static' && !nuxtOptions.dev,
|
||||
fullStatic: nuxtOptions.target === 'static' && !nuxtOptions._legacyGenerate,
|
||||
// @ts-ignore
|
||||
staticAssets: nuxtOptions.generate.staticAssets
|
||||
},
|
||||
|
@ -18,14 +18,19 @@ export default function (nuxt) {
|
||||
const sigmaContext = getsigmaContext(nuxt.options, nuxt.options.sigma || {})
|
||||
const sigmaDevContext = getsigmaContext(nuxt.options, { preset: 'dev' })
|
||||
|
||||
// Use nuxt as main hooks host
|
||||
// Connect hooks
|
||||
nuxt.addHooks(sigmaContext.nuxtHooks)
|
||||
nuxt.hook('close', () => sigmaContext._internal.hooks.callHook('close'))
|
||||
|
||||
nuxt.addHooks(sigmaDevContext.nuxtHooks)
|
||||
nuxt.hook('close', () => sigmaDevContext._internal.hooks.callHook('close'))
|
||||
sigmaDevContext._internal.hooks.hook('renderLoading',
|
||||
(req, res) => nuxt.callHook('server:nuxt:renderLoading', req, res))
|
||||
|
||||
// Replace nuxt server
|
||||
if (nuxt.server) {
|
||||
nuxt.server.__closed = true
|
||||
nuxt.server = createNuxt2DevServer(sigmaDevContext)
|
||||
nuxt.addHooks(sigmaDevContext.nuxtHooks)
|
||||
}
|
||||
|
||||
// serverMiddleware bridge
|
||||
@ -60,12 +65,16 @@ export default function (nuxt) {
|
||||
nuxt.options.build._minifyServer = false
|
||||
nuxt.options.build.standalone = false
|
||||
nuxt.hook('build:done', async () => {
|
||||
await build(nuxt.options.dev ? sigmaDevContext : sigmaContext)
|
||||
if (nuxt.options.dev) {
|
||||
await build(sigmaDevContext)
|
||||
} else if (!sigmaContext._nuxt.isStatic) {
|
||||
await build(sigmaContext)
|
||||
}
|
||||
})
|
||||
|
||||
// nude dev
|
||||
if (nuxt.options.dev) {
|
||||
nuxt.hook('sigma:compiled', () => { nuxt.server.watch() })
|
||||
sigmaDevContext._internal.hooks.hook('sigma:compiled', () => { nuxt.server.watch() })
|
||||
nuxt.hook('build:compile', ({ compiler }) => { compiler.outputFileSystem = wpfs })
|
||||
nuxt.hook('server:devMiddleware', (m) => { nuxt.server.setDevMiddleware(m) })
|
||||
}
|
||||
@ -74,17 +83,19 @@ export default function (nuxt) {
|
||||
nuxt.options.generate.dir = sigmaContext.output.publicDir
|
||||
nuxt.hook('generate:cache:ignore', (ignore: string[]) => {
|
||||
ignore.push(sigmaContext.output.dir)
|
||||
ignore.push(sigmaContext.output.serverDir)
|
||||
if (sigmaContext.output.publicDir) {
|
||||
ignore.push(sigmaContext.output.publicDir)
|
||||
}
|
||||
ignore.push(...sigmaContext.ignore)
|
||||
})
|
||||
|
||||
// generate:bfore is before webpack build that we need!
|
||||
nuxt.hook('generate:extendRoutes', async () => {
|
||||
await build(sigmaDevContext)
|
||||
await nuxt.server.reload()
|
||||
})
|
||||
|
||||
nuxt.hook('generate:done', async () => {
|
||||
await nuxt.server.close()
|
||||
await build(sigmaContext)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -73,11 +73,13 @@ export function createDevServer (sigmaContext: SigmaContext) {
|
||||
const proxy = createProxy()
|
||||
app.use((req, res) => {
|
||||
if (workerAddress) {
|
||||
proxy.web(req, res, { target: workerAddress })
|
||||
proxy.web(req, res, { target: workerAddress }, (err) => {
|
||||
console.error('[proxy]', err)
|
||||
})
|
||||
} else if (loadingMiddleware) {
|
||||
// TODO:serverIndex method is not exposed
|
||||
// loadingMiddleware(req, res)
|
||||
sigmaContext._internal.hooks.callHook('server:nuxt:renderLoading', req, res)
|
||||
sigmaContext._internal.hooks.callHook('renderLoading', req, res)
|
||||
} else {
|
||||
res.end('Worker not ready!')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user