mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +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<{
|
||||
src: string
|
||||
}>
|
||||
|
||||
relativeToBuild: (...args: string[]) => string
|
||||
routes: RouteLocationRaw[]
|
||||
supportedExtensions: string[]
|
||||
@ -123,7 +124,7 @@ export default class Builder {
|
||||
}
|
||||
}
|
||||
|
||||
resolveAppTemplate() {
|
||||
resolveAppTemplate () {
|
||||
// Resolve appDir
|
||||
const templatesDir = path.join(this.options.appDir, '_templates')
|
||||
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(',')}}`
|
||||
}
|
||||
|
||||
@ -351,7 +352,7 @@ export default class Builder {
|
||||
)
|
||||
}
|
||||
|
||||
addOptionalTemplates(templateContext) {
|
||||
addOptionalTemplates (templateContext) {
|
||||
if (this.options.build.indicator) {
|
||||
// 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), {
|
||||
cwd,
|
||||
follow: this.options.build.followSymlinks
|
||||
}))
|
||||
}
|
||||
|
||||
async resolveRelative(dir) {
|
||||
async resolveRelative (dir) {
|
||||
const dirPrefix = new RegExp(`^${dir}/`)
|
||||
return (await this.resolveFiles(dir)).map(file => ({ src: file.replace(dirPrefix, '') }))
|
||||
}
|
||||
@ -387,7 +388,7 @@ export default class Builder {
|
||||
templateVars.hasApp = false
|
||||
}
|
||||
|
||||
async resolveLayouts({ templateVars, templateFiles }) {
|
||||
async resolveLayouts ({ templateVars, templateFiles }) {
|
||||
if (!this.options.features.layouts) {
|
||||
return
|
||||
}
|
||||
@ -425,7 +426,7 @@ export default class Builder {
|
||||
}
|
||||
}
|
||||
|
||||
async resolvePages(templateContext) {
|
||||
async resolvePages (templateContext) {
|
||||
const { templateVars } = templateContext
|
||||
|
||||
const pagesDir = path.join(this.options.srcDir, this.options.dir.pages)
|
||||
@ -486,7 +487,7 @@ export default class Builder {
|
||||
this.routes = templateVars.router.routes
|
||||
}
|
||||
|
||||
async resolveStore({ templateVars, templateFiles }) {
|
||||
async resolveStore ({ templateVars, templateFiles }) {
|
||||
// Add store if needed
|
||||
if (!this.options.features.store || !this.options.store) {
|
||||
return
|
||||
@ -742,7 +743,7 @@ export default class Builder {
|
||||
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)
|
||||
|
||||
|
@ -5,7 +5,7 @@ export default class BuildContext {
|
||||
nuxt: Builder['nuxt']
|
||||
options: Builder['nuxt']['options']
|
||||
target: Builder['nuxt']['options']['target']
|
||||
|
||||
|
||||
constructor (builder: Builder) {
|
||||
this._builder = builder
|
||||
this.nuxt = builder.nuxt
|
||||
|
@ -26,7 +26,6 @@ export interface Command {
|
||||
|
||||
type Hooks = Parameters<Hookable['addHooks']>[0]
|
||||
|
||||
|
||||
export default class NuxtCommand extends Hookable {
|
||||
_argv: string[]
|
||||
_parsedArgv: null | ParsedArgs
|
||||
@ -123,7 +122,7 @@ export default class NuxtCommand extends Hookable {
|
||||
return this._parsedArgv
|
||||
}
|
||||
|
||||
async getNuxtConfig(extraOptions: Partial<CliConfiguration> = {}) {
|
||||
async getNuxtConfig (extraOptions: Partial<CliConfiguration> = {}) {
|
||||
// Flag to indicate nuxt is running with CLI (not programmatic)
|
||||
extraOptions._cli = true
|
||||
|
||||
@ -145,7 +144,6 @@ export default class NuxtCommand extends Hookable {
|
||||
}
|
||||
|
||||
async getNuxt (options: CliConfiguration) {
|
||||
|
||||
const nuxt = new Nuxt(options)
|
||||
await nuxt.ready()
|
||||
|
||||
|
@ -5,10 +5,10 @@ import serveStatic from 'serve-static'
|
||||
import compression from 'compression'
|
||||
import { getNuxtConfig } from 'src/config'
|
||||
import { TARGETS } from 'src/utils'
|
||||
import { common, server } from '../options'
|
||||
import { showBanner } from '../utils/banner'
|
||||
import { Listener } from 'src/server'
|
||||
import { Nuxt } from 'src/core'
|
||||
import { common, server } from '../options'
|
||||
import { showBanner } from '../utils/banner'
|
||||
import type NuxtCommand from '../command'
|
||||
|
||||
export default {
|
||||
|
@ -169,4 +169,4 @@ export default (): AppOptions => ({
|
||||
// if (typeof options.extensions === 'string') {
|
||||
// options.extensions = [options.extensions]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
@ -1,3 +1,4 @@
|
||||
import path from 'path'
|
||||
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
||||
import type { NextHandleFunction, Server as ConnectServer } from 'connect'
|
||||
import type { configHooksT } from 'hookable/types/types'
|
||||
@ -5,11 +6,10 @@ import ignore from 'ignore'
|
||||
import capitalize from 'lodash/capitalize'
|
||||
import env from 'std-env'
|
||||
import type { Configuration as WebpackConfiguration } from 'webpack'
|
||||
import path from 'path'
|
||||
import { TARGETS, MODES, Target, Mode } from 'src/utils'
|
||||
|
||||
import type { NormalizedConfiguration } from '../options'
|
||||
import Hookable from 'hookable'
|
||||
import type { NormalizedConfiguration } from '../options'
|
||||
|
||||
type IgnoreOptions = Parameters<typeof ignore>[0]
|
||||
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 { VueLoaderOptions } from 'vue-loader'
|
||||
import type {
|
||||
Configuration as WebpackConfiguration, WebpackPluginFunction,
|
||||
|
||||
Configuration as WebpackConfiguration, WebpackPluginFunction
|
||||
|
||||
} from 'webpack'
|
||||
import type { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
||||
import type { MiddlewareOptions as WebpackHotMiddlewareOptions, ClientOptions as WebpackHotMiddlewareClientOptions } from 'webpack-hot-middleware'
|
||||
|
||||
|
||||
interface WebpackEnv {
|
||||
isClient: boolean
|
||||
isDev: boolean
|
||||
@ -96,7 +94,6 @@ interface PostcssVariableMap {
|
||||
environmentVariables?: Record<string, string>
|
||||
}
|
||||
|
||||
|
||||
interface PostcssConfiguration {
|
||||
order?: PostcssOrderPreset | string[] | ((names: string[], presets: PostcssOrderPresetFunctions) => string[])
|
||||
plugins?: {
|
||||
@ -177,7 +174,7 @@ export default () => ({
|
||||
} as BabelOptions,
|
||||
/**
|
||||
* Enable cache of [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin#options) and [cache-loader](https://github.com/webpack-contrib/cache-loader#cache-loader)
|
||||
*
|
||||
*
|
||||
* ⚠️ Experimental
|
||||
* @default false
|
||||
*/
|
||||
@ -201,7 +198,7 @@ export default () => ({
|
||||
* Enables Common CSS Extraction using Vue Server Renderer guidelines.
|
||||
*
|
||||
* Using [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/) under the hood, all your CSS will be extracted into separate files, usually one per component. This allows caching your CSS and JavaScript separately and is worth a try in case you have a lot of global or shared CSS.
|
||||
*
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
extractCSS: false as boolean | Record<string, any>,
|
||||
@ -303,7 +300,7 @@ export default () => ({
|
||||
optimizeCSS: undefined as undefined | OptimizeCssAssetsWebpackPluginOptions | boolean,
|
||||
/**
|
||||
* Enable [thread-loader](https://github.com/webpack-contrib/thread-loader#thread-loader) in webpack building
|
||||
*
|
||||
*
|
||||
* ⚠️ Experimental
|
||||
* @default false
|
||||
*/
|
||||
@ -349,12 +346,12 @@ export default () => ({
|
||||
commons: true
|
||||
},
|
||||
/**
|
||||
* Creates special webpack bundle for SSR renderer.
|
||||
* Creates special webpack bundle for SSR renderer.
|
||||
* @default true for universal mode and `false` for spa mode
|
||||
*/
|
||||
ssr: undefined as undefined | boolean,
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
standalone: false,
|
||||
stats: {
|
||||
@ -371,7 +368,7 @@ export default () => ({
|
||||
*/
|
||||
templates: [] as Template[],
|
||||
/**
|
||||
* Terser plugin options. Set to `false` to disable this plugin. See https://github.com/webpack-contrib/terser-webpack-plugin
|
||||
* Terser plugin options. Set to `false` to disable this plugin. See https://github.com/webpack-contrib/terser-webpack-plugin
|
||||
*/
|
||||
terser: {} as TerserPluginOptions | boolean,
|
||||
// Name of NPM packages to be transpiled
|
||||
@ -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.
|
||||
*/
|
||||
watch: [] as string[],
|
||||
watch: [] as string[]
|
||||
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ export const getDefaultNuxtConfig = () =>
|
||||
cli: cli(),
|
||||
generate: generate(),
|
||||
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>
|
||||
|
@ -25,4 +25,4 @@ export default ({ env = {} }: { env?: ServerProcessEnv } = {}) => ({
|
||||
socket: env.UNIX_SOCKET ||
|
||||
env.npm_package_config_unix_socket,
|
||||
timing: false as false | { total: boolean }
|
||||
})
|
||||
})
|
||||
|
@ -10,8 +10,8 @@ import destr from 'destr'
|
||||
import * as rc from 'rc9'
|
||||
|
||||
import { LoadOptions } from 'src/core/load'
|
||||
import { defaultNuxtConfigFile } from './config'
|
||||
import { CliConfiguration, Configuration } from 'src/config/options'
|
||||
import { defaultNuxtConfigFile } from './config'
|
||||
|
||||
// @ts-ignore
|
||||
const isJest = typeof jest !== 'undefined'
|
||||
@ -71,7 +71,7 @@ export async function loadNuxtConfig ({
|
||||
// Clear cache
|
||||
clearRequireCache(configFile)
|
||||
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') {
|
||||
try {
|
||||
|
@ -7,9 +7,9 @@ import pick from 'lodash/pick'
|
||||
import uniq from 'lodash/uniq'
|
||||
import destr from 'destr'
|
||||
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 { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'
|
||||
import type { EnvConfig } from 'src/config/load'
|
||||
|
||||
interface InputConfiguration {
|
||||
appTemplatePath?: string
|
||||
@ -39,7 +39,7 @@ export interface CliConfiguration extends Configuration {
|
||||
_nuxtConfigFiles?: string[]
|
||||
}
|
||||
|
||||
export function getNuxtConfig(_options: Configuration) {
|
||||
export function getNuxtConfig (_options: Configuration) {
|
||||
// Prevent duplicate calls
|
||||
if ('__normalized__' in _options) {
|
||||
return _options
|
||||
@ -48,7 +48,7 @@ export function getNuxtConfig(_options: Configuration) {
|
||||
return normalizeConfig(_options as CliConfiguration)
|
||||
}
|
||||
|
||||
function normalizeConfig(_options: CliConfiguration) {
|
||||
function normalizeConfig (_options: CliConfiguration) {
|
||||
// Clone options to prevent unwanted side-effects
|
||||
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, 'serverMiddleware', Array.isArray(options.serverMiddleware) ? options.serverMiddleware : Object.entries(options.serverMiddleware)
|
||||
.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]>
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
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]
|
||||
} : 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> {
|
||||
(obj as { [key in K]: V })[key] = value
|
||||
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
|
||||
}
|
||||
|
||||
export function deleteProp<O extends Record<string, any>, K extends string>(obj: O, key: K): asserts obj is Exclude<O, K> {
|
||||
delete obj[key]
|
||||
export function deleteProp<O extends Record<string, any>, K extends string> (obj: O, key: K): asserts obj is Exclude<O, K> {
|
||||
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
|
||||
@ -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
|
||||
|
||||
export function mergeConfigs<Dest extends Record<string, any>, Source extends Record<string, any>>(dest: Dest, source: Source): Merge<Dest, Source> {
|
||||
return defaultsDeep(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)
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import consola from 'consola'
|
||||
import type { NormalizedConfiguration } from 'src/config'
|
||||
import { chainFn, sequence } from 'src/utils'
|
||||
|
||||
import Nuxt from './nuxt'
|
||||
import type { NuxtModule, ModuleHandler } from 'src/config/config/_common'
|
||||
import Nuxt from './nuxt'
|
||||
|
||||
interface TemplateInput {
|
||||
filename?: string
|
||||
@ -27,7 +27,7 @@ export default class ModuleContainer {
|
||||
handler: ModuleHandler
|
||||
}>
|
||||
|
||||
constructor(nuxt: Nuxt) {
|
||||
constructor (nuxt: Nuxt) {
|
||||
this.nuxt = nuxt
|
||||
this.options = nuxt.options
|
||||
this.requiredModules = {}
|
||||
@ -40,7 +40,7 @@ export default class ModuleContainer {
|
||||
}
|
||||
}
|
||||
|
||||
async ready() {
|
||||
async ready () {
|
||||
// Call before hook
|
||||
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)
|
||||
}
|
||||
|
||||
addVendor() {
|
||||
addVendor () {
|
||||
consola.warn('addVendor has been deprecated due to webpack4 optimization')
|
||||
}
|
||||
|
||||
addTemplate(template: TemplateInput | string) {
|
||||
addTemplate (template: TemplateInput | string) {
|
||||
if (!template) {
|
||||
throw new Error('Invalid template: ' + JSON.stringify(template))
|
||||
}
|
||||
@ -92,7 +92,7 @@ export default class ModuleContainer {
|
||||
return templateObj
|
||||
}
|
||||
|
||||
addPlugin(template: TemplateInput) {
|
||||
addPlugin (template: TemplateInput) {
|
||||
const { dst } = this.addTemplate(template)
|
||||
|
||||
// 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 layoutName = name || path.parse(src).name
|
||||
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)
|
||||
this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`
|
||||
}
|
||||
|
||||
addServerMiddleware(middleware: NormalizedConfiguration['serverMiddleware'][number]) {
|
||||
addServerMiddleware (middleware: NormalizedConfiguration['serverMiddleware'][number]) {
|
||||
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)
|
||||
}
|
||||
|
||||
extendRoutes(fn: NormalizedConfiguration['router']['extendRoutes']) {
|
||||
extendRoutes (fn: NormalizedConfiguration['router']['extendRoutes']) {
|
||||
this.options.router.extendRoutes = chainFn(
|
||||
this.options.router.extendRoutes,
|
||||
fn
|
||||
)
|
||||
}
|
||||
|
||||
requireModule(moduleOpts: NuxtModule) {
|
||||
requireModule (moduleOpts: NuxtModule) {
|
||||
return this.addModule(moduleOpts)
|
||||
}
|
||||
|
||||
async addModule(moduleOpts: NuxtModule) {
|
||||
async addModule (moduleOpts: NuxtModule) {
|
||||
let src: string | ModuleHandler
|
||||
let options: Record<string, any>
|
||||
let handler: ModuleHandler | ModuleHandler & { meta: { name: string } }
|
||||
|
@ -28,7 +28,7 @@ export default class Nuxt extends Hookable {
|
||||
render?: Server['app']
|
||||
showReady?: () => void
|
||||
|
||||
constructor(options: Configuration = {}) {
|
||||
constructor (options: Configuration = {}) {
|
||||
super(consola)
|
||||
|
||||
// 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' : '')
|
||||
}
|
||||
|
||||
ready() {
|
||||
ready () {
|
||||
if (!this._ready) {
|
||||
this._ready = this._init()
|
||||
}
|
||||
return this._ready
|
||||
}
|
||||
|
||||
async _init() {
|
||||
async _init () {
|
||||
if (this._initCalled) {
|
||||
return this
|
||||
}
|
||||
@ -108,7 +108,7 @@ export default class Nuxt extends Hookable {
|
||||
return this
|
||||
}
|
||||
|
||||
_initServer() {
|
||||
_initServer () {
|
||||
if (this.server) {
|
||||
return
|
||||
}
|
||||
@ -118,7 +118,7 @@ export default class Nuxt extends Hookable {
|
||||
defineAlias(this, this.server, ['renderRoute', 'renderAndGetWindow', 'listen'])
|
||||
}
|
||||
|
||||
async close(callback?: () => any | Promise<any>) {
|
||||
async close (callback?: () => any | Promise<any>) {
|
||||
await this.callHook('close', this)
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
|
@ -128,7 +128,7 @@ export default class Resolver {
|
||||
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 requiredModule: any
|
||||
|
||||
|
@ -31,7 +31,7 @@ export default class Generator {
|
||||
routes: Array<{ route: string } & Record<string, any>>
|
||||
generatedRoutes: Set<string>
|
||||
|
||||
constructor(nuxt: Nuxt, builder?: Builder) {
|
||||
constructor (nuxt: Nuxt, builder?: Builder) {
|
||||
this.nuxt = nuxt
|
||||
this.options = nuxt.options
|
||||
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...')
|
||||
await this.initiate({ build, init })
|
||||
|
||||
@ -80,7 +80,7 @@ export default class Generator {
|
||||
return { errors }
|
||||
}
|
||||
|
||||
async initiate({ build = true, init = true } = {}) {
|
||||
async initiate ({ build = true, init = true } = {}) {
|
||||
// Wait for nuxt be 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
|
||||
let generateRoutes = []
|
||||
if (this.options.router.mode !== 'hash') {
|
||||
@ -150,7 +150,7 @@ export default class Generator {
|
||||
return routes
|
||||
}
|
||||
|
||||
shouldGenerateRoute(route) {
|
||||
shouldGenerateRoute (route) {
|
||||
return this.options.generate.exclude.every((regex) => {
|
||||
if (typeof regex === 'string') {
|
||||
return regex !== route
|
||||
@ -159,7 +159,7 @@ export default class Generator {
|
||||
})
|
||||
}
|
||||
|
||||
getBuildConfig() {
|
||||
getBuildConfig () {
|
||||
try {
|
||||
return require(path.join(this.options.buildDir, 'nuxt/config.json'))
|
||||
} catch (err) {
|
||||
@ -167,11 +167,11 @@ export default class Generator {
|
||||
}
|
||||
}
|
||||
|
||||
getAppRoutes() {
|
||||
getAppRoutes () {
|
||||
return require(path.join(this.options.buildDir, 'routes.json'))
|
||||
}
|
||||
|
||||
async generateRoutes(routes) {
|
||||
async generateRoutes (routes) {
|
||||
const errors = []
|
||||
|
||||
this.routes = []
|
||||
@ -204,7 +204,7 @@ export default class Generator {
|
||||
return errors
|
||||
}
|
||||
|
||||
_formatErrors(errors) {
|
||||
_formatErrors (errors) {
|
||||
return errors
|
||||
.map(({ type, route, error }) => {
|
||||
const isHandled = type === 'handled'
|
||||
@ -223,7 +223,7 @@ export default class Generator {
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
async afterGenerate() {
|
||||
async afterGenerate () {
|
||||
const { fallback } = this.options.generate
|
||||
|
||||
// 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 + '`')
|
||||
}
|
||||
|
||||
async initDist() {
|
||||
async initDist () {
|
||||
// Clean destination folder
|
||||
await fsExtra.emptyDir(this.distPath)
|
||||
|
||||
@ -283,7 +283,7 @@ export default class Generator {
|
||||
await this.nuxt.callHook('export:distCopied', this)
|
||||
}
|
||||
|
||||
decorateWithPayloads(routes, generateRoutes) {
|
||||
decorateWithPayloads (routes, generateRoutes) {
|
||||
const routeMap = {}
|
||||
// Fill routeMap for known routes
|
||||
routes.forEach((route) => {
|
||||
@ -301,7 +301,7 @@ export default class Generator {
|
||||
return Object.values(routeMap)
|
||||
}
|
||||
|
||||
async generateRoute({ route, payload = {}, errors = [] }) {
|
||||
async generateRoute ({ route, payload = {}, errors = [] }) {
|
||||
let html
|
||||
const pageErrors = []
|
||||
|
||||
@ -415,7 +415,7 @@ export default class Generator {
|
||||
return true
|
||||
}
|
||||
|
||||
minifyHtml(html: string) {
|
||||
minifyHtml (html: string) {
|
||||
const minificationOptions = this.options.build.html.minify
|
||||
|
||||
if (!minificationOptions) {
|
||||
|
@ -43,6 +43,7 @@ export default class Server {
|
||||
spaTemplate?: TemplateExecutor
|
||||
errorTemplate?: TemplateExecutor
|
||||
}
|
||||
|
||||
serverContext: ServerContext
|
||||
|
||||
constructor (nuxt: Nuxt) {
|
||||
|
@ -10,4 +10,4 @@ export const MODES = {
|
||||
spa: 'spa'
|
||||
} as const
|
||||
|
||||
export type Mode = keyof typeof MODES
|
||||
export type Mode = keyof typeof MODES
|
||||
|
@ -67,7 +67,7 @@ interface AliasOptions {
|
||||
warn?: boolean
|
||||
}
|
||||
|
||||
export function defineAlias <O extends Record<string, any>>(
|
||||
export function defineAlias <O extends Record<string, any>> (
|
||||
src: O,
|
||||
target: Record<string, any>,
|
||||
prop: string | string[],
|
||||
|
@ -49,7 +49,7 @@ function cleanChildrenRoutes (routes: NuxtRouteConfig[], isChild = false, routeN
|
||||
routes.forEach((route) => {
|
||||
route.path = isChild ? route.path.replace('/', '') : route.path
|
||||
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('/')
|
||||
if (!isChild) {
|
||||
paths.shift()
|
||||
|
@ -15,7 +15,7 @@ async function promiseFinally<T> (
|
||||
return result
|
||||
}
|
||||
|
||||
export const timeout = function timeout <T>(
|
||||
export const timeout = function timeout <T> (
|
||||
fn: Promise<T>,
|
||||
ms: number,
|
||||
msg: string
|
||||
|
@ -4,10 +4,10 @@ import consola from 'consola'
|
||||
import template from 'lodash/template'
|
||||
import { TARGETS, isModernRequest, waitFor } from 'src/utils'
|
||||
|
||||
import ServerContext from 'src/server/context'
|
||||
import SPARenderer from './renderers/spa'
|
||||
import SSRRenderer from './renderers/ssr'
|
||||
import ModernRenderer from './renderers/modern'
|
||||
import ServerContext from 'src/server/context'
|
||||
|
||||
export default class VueRenderer {
|
||||
__closed?: boolean
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ServerContext from "nuxt/server/context"
|
||||
import ServerContext from 'nuxt/server/context'
|
||||
|
||||
export default class BaseRenderer {
|
||||
serverContext: ServerContext
|
||||
|
@ -258,7 +258,7 @@ export default class WebpackBaseConfig {
|
||||
alias () {
|
||||
return {
|
||||
...this.buildContext.options.alias,
|
||||
'app': this.buildContext.options.appDir,
|
||||
app: this.buildContext.options.appDir,
|
||||
'nuxt-build': this.buildContext.options.buildDir,
|
||||
'vue-meta': require.resolve(`vue-meta${this.isServer ? '' : '/dist/vue-meta.esm.browser.js'}`)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user