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