Nuxt/packages/nitro/src/index.ts

46 lines
1019 B
TypeScript
Raw Normal View History

import type { Module } from '@nuxt/types'
2020-11-05 11:28:39 +00:00
import { build, compileHTMLTemplate } from './build'
import { getoptions } from './config'
2020-11-05 11:28:39 +00:00
export default <Module> function slsModule () {
2020-11-05 11:28:39 +00:00
const { nuxt } = this
if (nuxt.options.dev) {
return
}
// Config
const options = getoptions(nuxt.options)
2020-11-05 11:28:39 +00:00
if (options.minify !== false) {
2020-11-05 11:28:39 +00:00
nuxt.options.build._minifyServer = true
}
nuxt.options.build.standalone = true
nuxt.options.generate.crawler = false
if (Array.isArray(nuxt.options.generate.routes)) {
nuxt.options.generate.routes = Array.from(new Set([
...nuxt.options.generate.routes,
...options.static
]))
}
2020-11-05 21:40:25 +00:00
if (options.nuxtHooks) {
nuxt.addHooks(options.nuxtHooks)
}
2020-11-05 11:28:39 +00:00
nuxt.hook('generate:cache:ignore', (ignore) => {
ignore.push(options.slsDir)
2020-11-05 11:28:39 +00:00
})
2020-11-05 12:02:57 +00:00
nuxt.hook('generate:page', (page) => {
// TODO: Use ssrContext
if (!options.static.includes(page.route)) {
2020-11-05 12:02:57 +00:00
page.exclude = true
}
})
nuxt.hook('generate:done', () => build(options))
2020-11-05 11:28:39 +00:00
}