mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
chore: lint with eslint
This commit is contained in:
parent
8ac0a7cec6
commit
d6ae2c73d9
@ -54,6 +54,7 @@ export default class Builder {
|
|||||||
plugins: Array<{
|
plugins: Array<{
|
||||||
src: string
|
src: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
relativeToBuild: (...args: string[]) => string
|
relativeToBuild: (...args: string[]) => string
|
||||||
routes: RouteLocationRaw[]
|
routes: RouteLocationRaw[]
|
||||||
supportedExtensions: string[]
|
supportedExtensions: string[]
|
||||||
@ -123,7 +124,7 @@ export default class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveAppTemplate() {
|
resolveAppTemplate () {
|
||||||
// Resolve appDir
|
// Resolve appDir
|
||||||
const templatesDir = path.join(this.options.appDir, '_templates')
|
const templatesDir = path.join(this.options.appDir, '_templates')
|
||||||
const files = globby.sync(path.join(templatesDir, '/**'))
|
const files = globby.sync(path.join(templatesDir, '/**'))
|
||||||
@ -265,7 +266,7 @@ export default class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
globPathWithExtensions(path: string) {
|
globPathWithExtensions (path: string) {
|
||||||
return `${path}/**/*.{${this.supportedExtensions.join(',')}}`
|
return `${path}/**/*.{${this.supportedExtensions.join(',')}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +352,7 @@ export default class Builder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
addOptionalTemplates(templateContext) {
|
addOptionalTemplates (templateContext) {
|
||||||
if (this.options.build.indicator) {
|
if (this.options.build.indicator) {
|
||||||
// templateContext.templateFiles.push('components/nuxt-build-indicator.vue')
|
// templateContext.templateFiles.push('components/nuxt-build-indicator.vue')
|
||||||
}
|
}
|
||||||
@ -361,14 +362,14 @@ export default class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveFiles(dir, cwd = this.options.srcDir) {
|
async resolveFiles (dir, cwd = this.options.srcDir) {
|
||||||
return this.ignore.filter(await glob(this.globPathWithExtensions(dir), {
|
return this.ignore.filter(await glob(this.globPathWithExtensions(dir), {
|
||||||
cwd,
|
cwd,
|
||||||
follow: this.options.build.followSymlinks
|
follow: this.options.build.followSymlinks
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveRelative(dir) {
|
async resolveRelative (dir) {
|
||||||
const dirPrefix = new RegExp(`^${dir}/`)
|
const dirPrefix = new RegExp(`^${dir}/`)
|
||||||
return (await this.resolveFiles(dir)).map(file => ({ src: file.replace(dirPrefix, '') }))
|
return (await this.resolveFiles(dir)).map(file => ({ src: file.replace(dirPrefix, '') }))
|
||||||
}
|
}
|
||||||
@ -387,7 +388,7 @@ export default class Builder {
|
|||||||
templateVars.hasApp = false
|
templateVars.hasApp = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveLayouts({ templateVars, templateFiles }) {
|
async resolveLayouts ({ templateVars, templateFiles }) {
|
||||||
if (!this.options.features.layouts) {
|
if (!this.options.features.layouts) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -425,7 +426,7 @@ export default class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolvePages(templateContext) {
|
async resolvePages (templateContext) {
|
||||||
const { templateVars } = templateContext
|
const { templateVars } = templateContext
|
||||||
|
|
||||||
const pagesDir = path.join(this.options.srcDir, this.options.dir.pages)
|
const pagesDir = path.join(this.options.srcDir, this.options.dir.pages)
|
||||||
@ -486,7 +487,7 @@ export default class Builder {
|
|||||||
this.routes = templateVars.router.routes
|
this.routes = templateVars.router.routes
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveStore({ templateVars, templateFiles }) {
|
async resolveStore ({ templateVars, templateFiles }) {
|
||||||
// Add store if needed
|
// Add store if needed
|
||||||
if (!this.options.features.store || !this.options.store) {
|
if (!this.options.features.store || !this.options.store) {
|
||||||
return
|
return
|
||||||
@ -742,7 +743,7 @@ export default class Builder {
|
|||||||
patterns.push(r(this.options.srcDir, this.options.dir.pages))
|
patterns.push(r(this.options.srcDir, this.options.dir.pages))
|
||||||
}
|
}
|
||||||
|
|
||||||
patterns = patterns.map((path) => upath.normalizeSafe(this.globPathWithExtensions(path)))
|
patterns = patterns.map(path => upath.normalizeSafe(this.globPathWithExtensions(path)))
|
||||||
|
|
||||||
const refreshFiles = debounce(() => this.generateRoutesAndFiles(), 200)
|
const refreshFiles = debounce(() => this.generateRoutesAndFiles(), 200)
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ export interface Command {
|
|||||||
|
|
||||||
type Hooks = Parameters<Hookable['addHooks']>[0]
|
type Hooks = Parameters<Hookable['addHooks']>[0]
|
||||||
|
|
||||||
|
|
||||||
export default class NuxtCommand extends Hookable {
|
export default class NuxtCommand extends Hookable {
|
||||||
_argv: string[]
|
_argv: string[]
|
||||||
_parsedArgv: null | ParsedArgs
|
_parsedArgv: null | ParsedArgs
|
||||||
@ -123,7 +122,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return this._parsedArgv
|
return this._parsedArgv
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNuxtConfig(extraOptions: Partial<CliConfiguration> = {}) {
|
async getNuxtConfig (extraOptions: Partial<CliConfiguration> = {}) {
|
||||||
// Flag to indicate nuxt is running with CLI (not programmatic)
|
// Flag to indicate nuxt is running with CLI (not programmatic)
|
||||||
extraOptions._cli = true
|
extraOptions._cli = true
|
||||||
|
|
||||||
@ -145,7 +144,6 @@ export default class NuxtCommand extends Hookable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getNuxt (options: CliConfiguration) {
|
async getNuxt (options: CliConfiguration) {
|
||||||
|
|
||||||
const nuxt = new Nuxt(options)
|
const nuxt = new Nuxt(options)
|
||||||
await nuxt.ready()
|
await nuxt.ready()
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ import serveStatic from 'serve-static'
|
|||||||
import compression from 'compression'
|
import compression from 'compression'
|
||||||
import { getNuxtConfig } from 'src/config'
|
import { getNuxtConfig } from 'src/config'
|
||||||
import { TARGETS } from 'src/utils'
|
import { TARGETS } from 'src/utils'
|
||||||
import { common, server } from '../options'
|
|
||||||
import { showBanner } from '../utils/banner'
|
|
||||||
import { Listener } from 'src/server'
|
import { Listener } from 'src/server'
|
||||||
import { Nuxt } from 'src/core'
|
import { Nuxt } from 'src/core'
|
||||||
|
import { common, server } from '../options'
|
||||||
|
import { showBanner } from '../utils/banner'
|
||||||
import type NuxtCommand from '../command'
|
import type NuxtCommand from '../command'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import path from 'path'
|
||||||
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
||||||
import type { NextHandleFunction, Server as ConnectServer } from 'connect'
|
import type { NextHandleFunction, Server as ConnectServer } from 'connect'
|
||||||
import type { configHooksT } from 'hookable/types/types'
|
import type { configHooksT } from 'hookable/types/types'
|
||||||
@ -5,11 +6,10 @@ import ignore from 'ignore'
|
|||||||
import capitalize from 'lodash/capitalize'
|
import capitalize from 'lodash/capitalize'
|
||||||
import env from 'std-env'
|
import env from 'std-env'
|
||||||
import type { Configuration as WebpackConfiguration } from 'webpack'
|
import type { Configuration as WebpackConfiguration } from 'webpack'
|
||||||
import path from 'path'
|
|
||||||
import { TARGETS, MODES, Target, Mode } from 'src/utils'
|
import { TARGETS, MODES, Target, Mode } from 'src/utils'
|
||||||
|
|
||||||
import type { NormalizedConfiguration } from '../options'
|
|
||||||
import Hookable from 'hookable'
|
import Hookable from 'hookable'
|
||||||
|
import type { NormalizedConfiguration } from '../options'
|
||||||
|
|
||||||
type IgnoreOptions = Parameters<typeof ignore>[0]
|
type IgnoreOptions = Parameters<typeof ignore>[0]
|
||||||
type IgnoreInstance = ReturnType<typeof ignore>
|
type IgnoreInstance = ReturnType<typeof ignore>
|
||||||
|
@ -13,14 +13,12 @@ import type { Options as PugOptions } from 'pug'
|
|||||||
import type { TerserPluginOptions } from 'terser-webpack-plugin'
|
import type { TerserPluginOptions } from 'terser-webpack-plugin'
|
||||||
import type { VueLoaderOptions } from 'vue-loader'
|
import type { VueLoaderOptions } from 'vue-loader'
|
||||||
import type {
|
import type {
|
||||||
Configuration as WebpackConfiguration, WebpackPluginFunction,
|
Configuration as WebpackConfiguration, WebpackPluginFunction
|
||||||
|
|
||||||
|
|
||||||
} from 'webpack'
|
} from 'webpack'
|
||||||
import type { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
import type { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
||||||
import type { MiddlewareOptions as WebpackHotMiddlewareOptions, ClientOptions as WebpackHotMiddlewareClientOptions } from 'webpack-hot-middleware'
|
import type { MiddlewareOptions as WebpackHotMiddlewareOptions, ClientOptions as WebpackHotMiddlewareClientOptions } from 'webpack-hot-middleware'
|
||||||
|
|
||||||
|
|
||||||
interface WebpackEnv {
|
interface WebpackEnv {
|
||||||
isClient: boolean
|
isClient: boolean
|
||||||
isDev: boolean
|
isDev: boolean
|
||||||
@ -96,7 +94,6 @@ interface PostcssVariableMap {
|
|||||||
environmentVariables?: Record<string, string>
|
environmentVariables?: Record<string, string>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface PostcssConfiguration {
|
interface PostcssConfiguration {
|
||||||
order?: PostcssOrderPreset | string[] | ((names: string[], presets: PostcssOrderPresetFunctions) => string[])
|
order?: PostcssOrderPreset | string[] | ((names: string[], presets: PostcssOrderPresetFunctions) => string[])
|
||||||
plugins?: {
|
plugins?: {
|
||||||
@ -380,6 +377,6 @@ export default () => ({
|
|||||||
/**
|
/**
|
||||||
* You can provide your custom files to watch and regenerate after changes. This feature is specially useful for using with modules.
|
* You can provide your custom files to watch and regenerate after changes. This feature is specially useful for using with modules.
|
||||||
*/
|
*/
|
||||||
watch: [] as string[],
|
watch: [] as string[]
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -26,7 +26,7 @@ export const getDefaultNuxtConfig = () =>
|
|||||||
cli: cli(),
|
cli: cli(),
|
||||||
generate: generate(),
|
generate: generate(),
|
||||||
export: undefined as undefined | GenerateOptions,
|
export: undefined as undefined | GenerateOptions,
|
||||||
telemetry: undefined as undefined | boolean,
|
telemetry: undefined as undefined | boolean
|
||||||
})
|
})
|
||||||
|
|
||||||
export type DefaultConfiguration = ReturnType<typeof getDefaultNuxtConfig>
|
export type DefaultConfiguration = ReturnType<typeof getDefaultNuxtConfig>
|
@ -10,8 +10,8 @@ import destr from 'destr'
|
|||||||
import * as rc from 'rc9'
|
import * as rc from 'rc9'
|
||||||
|
|
||||||
import { LoadOptions } from 'src/core/load'
|
import { LoadOptions } from 'src/core/load'
|
||||||
import { defaultNuxtConfigFile } from './config'
|
|
||||||
import { CliConfiguration, Configuration } from 'src/config/options'
|
import { CliConfiguration, Configuration } from 'src/config/options'
|
||||||
|
import { defaultNuxtConfigFile } from './config'
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const isJest = typeof jest !== 'undefined'
|
const isJest = typeof jest !== 'undefined'
|
||||||
@ -71,7 +71,7 @@ export async function loadNuxtConfig ({
|
|||||||
// Clear cache
|
// Clear cache
|
||||||
clearRequireCache(configFile)
|
clearRequireCache(configFile)
|
||||||
const _require = createRequire(module)
|
const _require = createRequire(module)
|
||||||
let _config: Configuration | ((ctx: Record<string, any>) => Promise<Configuration>) = interopDefault(_require(configFile) || {})
|
const _config: Configuration | ((ctx: Record<string, any>) => Promise<Configuration>) = interopDefault(_require(configFile) || {})
|
||||||
|
|
||||||
if (typeof _config === 'function') {
|
if (typeof _config === 'function') {
|
||||||
try {
|
try {
|
||||||
|
@ -7,9 +7,9 @@ import pick from 'lodash/pick'
|
|||||||
import uniq from 'lodash/uniq'
|
import uniq from 'lodash/uniq'
|
||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { TARGETS, MODES, guardDir, isNonEmptyString, isPureObject, isUrl, getMainModule, urlJoin, getPKG } from 'src/utils'
|
import { TARGETS, MODES, guardDir, isNonEmptyString, isPureObject, isUrl, getMainModule, urlJoin, getPKG } from 'src/utils'
|
||||||
|
import type { EnvConfig } from 'src/config/load'
|
||||||
import { DefaultConfiguration, defaultNuxtConfigFile, getDefaultNuxtConfig } from './config'
|
import { DefaultConfiguration, defaultNuxtConfigFile, getDefaultNuxtConfig } from './config'
|
||||||
import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'
|
import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'
|
||||||
import type { EnvConfig } from 'src/config/load'
|
|
||||||
|
|
||||||
interface InputConfiguration {
|
interface InputConfiguration {
|
||||||
appTemplatePath?: string
|
appTemplatePath?: string
|
||||||
@ -39,7 +39,7 @@ export interface CliConfiguration extends Configuration {
|
|||||||
_nuxtConfigFiles?: string[]
|
_nuxtConfigFiles?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNuxtConfig(_options: Configuration) {
|
export function getNuxtConfig (_options: Configuration) {
|
||||||
// Prevent duplicate calls
|
// Prevent duplicate calls
|
||||||
if ('__normalized__' in _options) {
|
if ('__normalized__' in _options) {
|
||||||
return _options
|
return _options
|
||||||
@ -48,7 +48,7 @@ export function getNuxtConfig(_options: Configuration) {
|
|||||||
return normalizeConfig(_options as CliConfiguration)
|
return normalizeConfig(_options as CliConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeConfig(_options: CliConfiguration) {
|
function normalizeConfig (_options: CliConfiguration) {
|
||||||
// Clone options to prevent unwanted side-effects
|
// Clone options to prevent unwanted side-effects
|
||||||
const _config: CliConfiguration = Object.assign({}, _options)
|
const _config: CliConfiguration = Object.assign({}, _options)
|
||||||
|
|
||||||
@ -382,7 +382,6 @@ function normalizeConfig(_options: CliConfiguration) {
|
|||||||
overrideProp(options.server, 'timing', { total: true, ...options.server.timing })
|
overrideProp(options.server, 'timing', { total: true, ...options.server.timing })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
overrideProp(options, 'serverMiddleware', Array.isArray(options.serverMiddleware) ? options.serverMiddleware : Object.entries(options.serverMiddleware)
|
overrideProp(options, 'serverMiddleware', Array.isArray(options.serverMiddleware) ? options.serverMiddleware : Object.entries(options.serverMiddleware)
|
||||||
.map(([path, handler]) => ({ path, handler }))
|
.map(([path, handler]) => ({ path, handler }))
|
||||||
)
|
)
|
||||||
|
@ -4,20 +4,20 @@ export type Optional<T> = {
|
|||||||
-readonly [K in keyof T]?: T[K] extends Function ? T[K] : T[K] extends RegExp ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends Array<infer R> ? Array<R> : Optional<T[K]>
|
-readonly [K in keyof T]?: T[K] extends Function ? T[K] : T[K] extends RegExp ? T[K] : T[K] extends Promise<any> ? T[K] : T[K] extends Array<infer R> ? Array<R> : Optional<T[K]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setProp<O extends Record<string, any>, K extends string, V>(obj: O, key: K, value: V): asserts obj is O & { [key in K]: V } {
|
export function setProp<O extends Record<string, any>, K extends string, V> (obj: O, key: K, value: V): asserts obj is O & { [key in K]: V } {
|
||||||
(obj as { [key in K]: V })[key] = value
|
(obj as { [key in K]: V })[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
type Override<O extends Record<string, any>, K extends keyof O, V> = K extends Array<infer A> ? {
|
type Override<O extends Record<string, any>, K extends keyof O, V> = K extends Array<infer A> ? {
|
||||||
[P in keyof O]: K extends P ? O[P] extends Array<infer T> ? Array<A & T> : K | O[P] : O[P]
|
[P in keyof O]: K extends P ? O[P] extends Array<infer T> ? Array<A & T> : K | O[P] : O[P]
|
||||||
} : O & { [key in K]: V }
|
} : O & { [key in K]: V }
|
||||||
|
|
||||||
export function overrideProp<O extends Record<string, any>, K extends keyof O, V>(obj: O, key: K, value: V): asserts obj is Override<O, K, V> {
|
export function overrideProp<O extends Record<string, any>, K extends keyof O, V> (obj: O, key: K, value: V): asserts obj is Override<O, K, V> {
|
||||||
(obj as { [key in K]: V })[key] = value
|
(obj as { [key in K]: V })[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteProp<O extends Record<string, any>, K extends string>(obj: O, key: K): asserts obj is Exclude<O, K> {
|
export function deleteProp<O extends Record<string, any>, K extends string> (obj: O, key: K): asserts obj is Exclude<O, K> {
|
||||||
delete obj[key]
|
delete obj[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
type MergeArrays<S, T> = S extends Array<infer A1> ? T extends Array<infer A2> ? Array<A1 | A2> : T | Array<A1> : T | S
|
type MergeArrays<S, T> = S extends Array<infer A1> ? T extends Array<infer A2> ? Array<A1 | A2> : T | Array<A1> : T | S
|
||||||
@ -33,6 +33,6 @@ type Merge<S, T> = S extends Array<any> ? MergeArrays<S, T> : S extends Function
|
|||||||
|
|
||||||
// T extends Array<infer A> ? Array<Merged<A, S>> : T
|
// T extends Array<infer A> ? Array<Merged<A, S>> : T
|
||||||
|
|
||||||
export function mergeConfigs<Dest extends Record<string, any>, Source extends Record<string, any>>(dest: Dest, source: Source): Merge<Dest, Source> {
|
export function mergeConfigs<Dest extends Record<string, any>, Source extends Record<string, any>> (dest: Dest, source: Source): Merge<Dest, Source> {
|
||||||
return defaultsDeep(dest, source)
|
return defaultsDeep(dest, source)
|
||||||
}
|
}
|
@ -6,8 +6,8 @@ import consola from 'consola'
|
|||||||
import type { NormalizedConfiguration } from 'src/config'
|
import type { NormalizedConfiguration } from 'src/config'
|
||||||
import { chainFn, sequence } from 'src/utils'
|
import { chainFn, sequence } from 'src/utils'
|
||||||
|
|
||||||
import Nuxt from './nuxt'
|
|
||||||
import type { NuxtModule, ModuleHandler } from 'src/config/config/_common'
|
import type { NuxtModule, ModuleHandler } from 'src/config/config/_common'
|
||||||
|
import Nuxt from './nuxt'
|
||||||
|
|
||||||
interface TemplateInput {
|
interface TemplateInput {
|
||||||
filename?: string
|
filename?: string
|
||||||
@ -27,7 +27,7 @@ export default class ModuleContainer {
|
|||||||
handler: ModuleHandler
|
handler: ModuleHandler
|
||||||
}>
|
}>
|
||||||
|
|
||||||
constructor(nuxt: Nuxt) {
|
constructor (nuxt: Nuxt) {
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
this.requiredModules = {}
|
this.requiredModules = {}
|
||||||
@ -40,7 +40,7 @@ export default class ModuleContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async ready() {
|
async ready () {
|
||||||
// Call before hook
|
// Call before hook
|
||||||
await this.nuxt.callHook('modules:before', this, this.options.modules)
|
await this.nuxt.callHook('modules:before', this, this.options.modules)
|
||||||
|
|
||||||
@ -59,11 +59,11 @@ export default class ModuleContainer {
|
|||||||
await this.nuxt.callHook('modules:done', this)
|
await this.nuxt.callHook('modules:done', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
addVendor() {
|
addVendor () {
|
||||||
consola.warn('addVendor has been deprecated due to webpack4 optimization')
|
consola.warn('addVendor has been deprecated due to webpack4 optimization')
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate(template: TemplateInput | string) {
|
addTemplate (template: TemplateInput | string) {
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error('Invalid template: ' + JSON.stringify(template))
|
throw new Error('Invalid template: ' + JSON.stringify(template))
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ export default class ModuleContainer {
|
|||||||
return templateObj
|
return templateObj
|
||||||
}
|
}
|
||||||
|
|
||||||
addPlugin(template: TemplateInput) {
|
addPlugin (template: TemplateInput) {
|
||||||
const { dst } = this.addTemplate(template)
|
const { dst } = this.addTemplate(template)
|
||||||
|
|
||||||
// Add to nuxt plugins
|
// Add to nuxt plugins
|
||||||
@ -104,7 +104,7 @@ export default class ModuleContainer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addLayout(template: TemplateInput, name: string) {
|
addLayout (template: TemplateInput, name: string) {
|
||||||
const { dst, src } = this.addTemplate(template)
|
const { dst, src } = this.addTemplate(template)
|
||||||
const layoutName = name || path.parse(src).name
|
const layoutName = name || path.parse(src).name
|
||||||
const layout = this.options.layouts[layoutName]
|
const layout = this.options.layouts[layoutName]
|
||||||
@ -122,31 +122,31 @@ export default class ModuleContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addErrorLayout(dst: string) {
|
addErrorLayout (dst: string) {
|
||||||
const relativeBuildDir = path.relative(this.options.rootDir, this.options.buildDir)
|
const relativeBuildDir = path.relative(this.options.rootDir, this.options.buildDir)
|
||||||
this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`
|
this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`
|
||||||
}
|
}
|
||||||
|
|
||||||
addServerMiddleware(middleware: NormalizedConfiguration['serverMiddleware'][number]) {
|
addServerMiddleware (middleware: NormalizedConfiguration['serverMiddleware'][number]) {
|
||||||
this.options.serverMiddleware.push(middleware)
|
this.options.serverMiddleware.push(middleware)
|
||||||
}
|
}
|
||||||
|
|
||||||
extendBuild(fn: NormalizedConfiguration['build']['extend']) {
|
extendBuild (fn: NormalizedConfiguration['build']['extend']) {
|
||||||
this.options.build.extend = chainFn(this.options.build.extend, fn)
|
this.options.build.extend = chainFn(this.options.build.extend, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
extendRoutes(fn: NormalizedConfiguration['router']['extendRoutes']) {
|
extendRoutes (fn: NormalizedConfiguration['router']['extendRoutes']) {
|
||||||
this.options.router.extendRoutes = chainFn(
|
this.options.router.extendRoutes = chainFn(
|
||||||
this.options.router.extendRoutes,
|
this.options.router.extendRoutes,
|
||||||
fn
|
fn
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
requireModule(moduleOpts: NuxtModule) {
|
requireModule (moduleOpts: NuxtModule) {
|
||||||
return this.addModule(moduleOpts)
|
return this.addModule(moduleOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
async addModule(moduleOpts: NuxtModule) {
|
async addModule (moduleOpts: NuxtModule) {
|
||||||
let src: string | ModuleHandler
|
let src: string | ModuleHandler
|
||||||
let options: Record<string, any>
|
let options: Record<string, any>
|
||||||
let handler: ModuleHandler | ModuleHandler & { meta: { name: string } }
|
let handler: ModuleHandler | ModuleHandler & { meta: { name: string } }
|
||||||
|
@ -28,7 +28,7 @@ export default class Nuxt extends Hookable {
|
|||||||
render?: Server['app']
|
render?: Server['app']
|
||||||
showReady?: () => void
|
showReady?: () => void
|
||||||
|
|
||||||
constructor(options: Configuration = {}) {
|
constructor (options: Configuration = {}) {
|
||||||
super(consola)
|
super(consola)
|
||||||
|
|
||||||
// Assign options and apply defaults
|
// Assign options and apply defaults
|
||||||
@ -70,18 +70,18 @@ export default class Nuxt extends Hookable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static get version() {
|
static get version () {
|
||||||
return `v${version}` + (global.__NUXT_DEV__ ? '-development' : '')
|
return `v${version}` + (global.__NUXT_DEV__ ? '-development' : '')
|
||||||
}
|
}
|
||||||
|
|
||||||
ready() {
|
ready () {
|
||||||
if (!this._ready) {
|
if (!this._ready) {
|
||||||
this._ready = this._init()
|
this._ready = this._init()
|
||||||
}
|
}
|
||||||
return this._ready
|
return this._ready
|
||||||
}
|
}
|
||||||
|
|
||||||
async _init() {
|
async _init () {
|
||||||
if (this._initCalled) {
|
if (this._initCalled) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ export default class Nuxt extends Hookable {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
_initServer() {
|
_initServer () {
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ export default class Nuxt extends Hookable {
|
|||||||
defineAlias(this, this.server, ['renderRoute', 'renderAndGetWindow', 'listen'])
|
defineAlias(this, this.server, ['renderRoute', 'renderAndGetWindow', 'listen'])
|
||||||
}
|
}
|
||||||
|
|
||||||
async close(callback?: () => any | Promise<any>) {
|
async close (callback?: () => any | Promise<any>) {
|
||||||
await this.callHook('close', this)
|
await this.callHook('close', this)
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
|
@ -128,7 +128,7 @@ export default class Resolver {
|
|||||||
throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`)
|
throw new Error(`Cannot resolve "${path}" from "${resolvedPath}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
requireModule <T>(path: string, { useESM, isAlias, interopDefault }: RequireModuleOptions = {}): T {
|
requireModule <T> (path: string, { useESM, isAlias, interopDefault }: RequireModuleOptions = {}): T {
|
||||||
let resolvedPath = path
|
let resolvedPath = path
|
||||||
let requiredModule: any
|
let requiredModule: any
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ export default class Generator {
|
|||||||
routes: Array<{ route: string } & Record<string, any>>
|
routes: Array<{ route: string } & Record<string, any>>
|
||||||
generatedRoutes: Set<string>
|
generatedRoutes: Set<string>
|
||||||
|
|
||||||
constructor(nuxt: Nuxt, builder?: Builder) {
|
constructor (nuxt: Nuxt, builder?: Builder) {
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
this.builder = builder
|
this.builder = builder
|
||||||
@ -53,7 +53,7 @@ export default class Generator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async generate({ build = true, init = true } = {}) {
|
async generate ({ build = true, init = true } = {}) {
|
||||||
consola.debug('Initializing generator...')
|
consola.debug('Initializing generator...')
|
||||||
await this.initiate({ build, init })
|
await this.initiate({ build, init })
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ export default class Generator {
|
|||||||
return { errors }
|
return { errors }
|
||||||
}
|
}
|
||||||
|
|
||||||
async initiate({ build = true, init = true } = {}) {
|
async initiate ({ build = true, init = true } = {}) {
|
||||||
// Wait for nuxt be ready
|
// Wait for nuxt be ready
|
||||||
await this.nuxt.ready()
|
await this.nuxt.ready()
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ export default class Generator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async initRoutes(...args) {
|
async initRoutes (...args) {
|
||||||
// Resolve config.generate.routes promises before generating the routes
|
// Resolve config.generate.routes promises before generating the routes
|
||||||
let generateRoutes = []
|
let generateRoutes = []
|
||||||
if (this.options.router.mode !== 'hash') {
|
if (this.options.router.mode !== 'hash') {
|
||||||
@ -150,7 +150,7 @@ export default class Generator {
|
|||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldGenerateRoute(route) {
|
shouldGenerateRoute (route) {
|
||||||
return this.options.generate.exclude.every((regex) => {
|
return this.options.generate.exclude.every((regex) => {
|
||||||
if (typeof regex === 'string') {
|
if (typeof regex === 'string') {
|
||||||
return regex !== route
|
return regex !== route
|
||||||
@ -159,7 +159,7 @@ export default class Generator {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getBuildConfig() {
|
getBuildConfig () {
|
||||||
try {
|
try {
|
||||||
return require(path.join(this.options.buildDir, 'nuxt/config.json'))
|
return require(path.join(this.options.buildDir, 'nuxt/config.json'))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -167,11 +167,11 @@ export default class Generator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAppRoutes() {
|
getAppRoutes () {
|
||||||
return require(path.join(this.options.buildDir, 'routes.json'))
|
return require(path.join(this.options.buildDir, 'routes.json'))
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateRoutes(routes) {
|
async generateRoutes (routes) {
|
||||||
const errors = []
|
const errors = []
|
||||||
|
|
||||||
this.routes = []
|
this.routes = []
|
||||||
@ -204,7 +204,7 @@ export default class Generator {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
_formatErrors(errors) {
|
_formatErrors (errors) {
|
||||||
return errors
|
return errors
|
||||||
.map(({ type, route, error }) => {
|
.map(({ type, route, error }) => {
|
||||||
const isHandled = type === 'handled'
|
const isHandled = type === 'handled'
|
||||||
@ -223,7 +223,7 @@ export default class Generator {
|
|||||||
.join('\n')
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterGenerate() {
|
async afterGenerate () {
|
||||||
const { fallback } = this.options.generate
|
const { fallback } = this.options.generate
|
||||||
|
|
||||||
// Disable SPA fallback if value isn't a non-empty string
|
// Disable SPA fallback if value isn't a non-empty string
|
||||||
@ -255,7 +255,7 @@ export default class Generator {
|
|||||||
consola.success('Client-side fallback created: `' + fallback + '`')
|
consola.success('Client-side fallback created: `' + fallback + '`')
|
||||||
}
|
}
|
||||||
|
|
||||||
async initDist() {
|
async initDist () {
|
||||||
// Clean destination folder
|
// Clean destination folder
|
||||||
await fsExtra.emptyDir(this.distPath)
|
await fsExtra.emptyDir(this.distPath)
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ export default class Generator {
|
|||||||
await this.nuxt.callHook('export:distCopied', this)
|
await this.nuxt.callHook('export:distCopied', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
decorateWithPayloads(routes, generateRoutes) {
|
decorateWithPayloads (routes, generateRoutes) {
|
||||||
const routeMap = {}
|
const routeMap = {}
|
||||||
// Fill routeMap for known routes
|
// Fill routeMap for known routes
|
||||||
routes.forEach((route) => {
|
routes.forEach((route) => {
|
||||||
@ -301,7 +301,7 @@ export default class Generator {
|
|||||||
return Object.values(routeMap)
|
return Object.values(routeMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateRoute({ route, payload = {}, errors = [] }) {
|
async generateRoute ({ route, payload = {}, errors = [] }) {
|
||||||
let html
|
let html
|
||||||
const pageErrors = []
|
const pageErrors = []
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ export default class Generator {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
minifyHtml(html: string) {
|
minifyHtml (html: string) {
|
||||||
const minificationOptions = this.options.build.html.minify
|
const minificationOptions = this.options.build.html.minify
|
||||||
|
|
||||||
if (!minificationOptions) {
|
if (!minificationOptions) {
|
||||||
|
@ -43,6 +43,7 @@ export default class Server {
|
|||||||
spaTemplate?: TemplateExecutor
|
spaTemplate?: TemplateExecutor
|
||||||
errorTemplate?: TemplateExecutor
|
errorTemplate?: TemplateExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
serverContext: ServerContext
|
serverContext: ServerContext
|
||||||
|
|
||||||
constructor (nuxt: Nuxt) {
|
constructor (nuxt: Nuxt) {
|
||||||
|
@ -67,7 +67,7 @@ interface AliasOptions {
|
|||||||
warn?: boolean
|
warn?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defineAlias <O extends Record<string, any>>(
|
export function defineAlias <O extends Record<string, any>> (
|
||||||
src: O,
|
src: O,
|
||||||
target: Record<string, any>,
|
target: Record<string, any>,
|
||||||
prop: string | string[],
|
prop: string | string[],
|
||||||
|
@ -49,7 +49,7 @@ function cleanChildrenRoutes (routes: NuxtRouteConfig[], isChild = false, routeN
|
|||||||
routes.forEach((route) => {
|
routes.forEach((route) => {
|
||||||
route.path = isChild ? route.path.replace('/', '') : route.path
|
route.path = isChild ? route.path.replace('/', '') : route.path
|
||||||
if (route.path.includes('?')) {
|
if (route.path.includes('?')) {
|
||||||
const names = typeof route.name === 'string' && route.name.split(routeNameSplitter) || []
|
const names = typeof route.name === 'string' && route.name.split(routeNameSplitter) || []
|
||||||
const paths = route.path.split('/')
|
const paths = route.path.split('/')
|
||||||
if (!isChild) {
|
if (!isChild) {
|
||||||
paths.shift()
|
paths.shift()
|
||||||
|
@ -15,7 +15,7 @@ async function promiseFinally<T> (
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const timeout = function timeout <T>(
|
export const timeout = function timeout <T> (
|
||||||
fn: Promise<T>,
|
fn: Promise<T>,
|
||||||
ms: number,
|
ms: number,
|
||||||
msg: string
|
msg: string
|
||||||
|
@ -4,10 +4,10 @@ import consola from 'consola'
|
|||||||
import template from 'lodash/template'
|
import template from 'lodash/template'
|
||||||
import { TARGETS, isModernRequest, waitFor } from 'src/utils'
|
import { TARGETS, isModernRequest, waitFor } from 'src/utils'
|
||||||
|
|
||||||
|
import ServerContext from 'src/server/context'
|
||||||
import SPARenderer from './renderers/spa'
|
import SPARenderer from './renderers/spa'
|
||||||
import SSRRenderer from './renderers/ssr'
|
import SSRRenderer from './renderers/ssr'
|
||||||
import ModernRenderer from './renderers/modern'
|
import ModernRenderer from './renderers/modern'
|
||||||
import ServerContext from 'src/server/context'
|
|
||||||
|
|
||||||
export default class VueRenderer {
|
export default class VueRenderer {
|
||||||
__closed?: boolean
|
__closed?: boolean
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import ServerContext from "nuxt/server/context"
|
import ServerContext from 'nuxt/server/context'
|
||||||
|
|
||||||
export default class BaseRenderer {
|
export default class BaseRenderer {
|
||||||
serverContext: ServerContext
|
serverContext: ServerContext
|
||||||
|
@ -258,7 +258,7 @@ export default class WebpackBaseConfig {
|
|||||||
alias () {
|
alias () {
|
||||||
return {
|
return {
|
||||||
...this.buildContext.options.alias,
|
...this.buildContext.options.alias,
|
||||||
'app': this.buildContext.options.appDir,
|
app: this.buildContext.options.appDir,
|
||||||
'nuxt-build': this.buildContext.options.buildDir,
|
'nuxt-build': this.buildContext.options.buildDir,
|
||||||
'vue-meta': require.resolve(`vue-meta${this.isServer ? '' : '/dist/vue-meta.esm.browser.js'}`)
|
'vue-meta': require.resolve(`vue-meta${this.isServer ? '' : '/dist/vue-meta.esm.browser.js'}`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user