mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
feat: shared logger and silent test logs (#3259)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
ad52b795e2
commit
467ab693b9
@ -29,7 +29,6 @@
|
|||||||
"@vue/composition-api": "^1.4.6",
|
"@vue/composition-api": "^1.4.6",
|
||||||
"@vueuse/head": "^0.7.5",
|
"@vueuse/head": "^0.7.5",
|
||||||
"acorn": "^8.7.0",
|
"acorn": "^8.7.0",
|
||||||
"consola": "^2.15.3",
|
|
||||||
"cookie-es": "^0.5.0",
|
"cookie-es": "^0.5.0",
|
||||||
"defu": "^5.0.1",
|
"defu": "^5.0.1",
|
||||||
"destr": "^1.1.0",
|
"destr": "^1.1.0",
|
||||||
|
@ -2,7 +2,7 @@ import { resolve } from 'pathe'
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { createVuePlugin } from 'vite-plugin-vue2'
|
import { createVuePlugin } from 'vite-plugin-vue2'
|
||||||
import PluginLegacy from '@vitejs/plugin-legacy'
|
import PluginLegacy from '@vitejs/plugin-legacy'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { devStyleSSRPlugin } from '../../../vite/src/plugins/dev-ssr-css'
|
import { devStyleSSRPlugin } from '../../../vite/src/plugins/dev-ssr-css'
|
||||||
import { jsxPlugin } from './plugins/jsx'
|
import { jsxPlugin } from './plugins/jsx'
|
||||||
@ -54,9 +54,9 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
// Production build
|
// Production build
|
||||||
if (!ctx.nuxt.options.dev) {
|
if (!ctx.nuxt.options.dev) {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
consola.info('Building client...')
|
logger.info('Building client...')
|
||||||
await vite.build(clientConfig)
|
await vite.build(clientConfig)
|
||||||
consola.success(`Client built in ${Date.now() - start}ms`)
|
logger.success(`Client built in ${Date.now() - start}ms`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import consola from 'consola'
|
import { logger, addPluginTemplate, defineNuxtModule } from '@nuxt/kit'
|
||||||
import { addPluginTemplate, defineNuxtModule } from '@nuxt/kit'
|
|
||||||
import { version } from '../../package.json'
|
import { version } from '../../package.json'
|
||||||
import { middlewareTemplate, storeTemplate } from './templates'
|
import { middlewareTemplate, storeTemplate } from './templates'
|
||||||
import type { ViteOptions } from './types'
|
import type { ViteOptions } from './types'
|
||||||
@ -15,9 +14,9 @@ export default defineNuxtModule<ViteOptions>({
|
|||||||
nuxt.options.cli.badgeMessages.push(`⚡ Vite Mode Enabled (v${version})`)
|
nuxt.options.cli.badgeMessages.push(`⚡ Vite Mode Enabled (v${version})`)
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
if (viteOptions.experimentWarning !== false && !nuxt.options.test) {
|
if (viteOptions.experimentWarning !== false && !nuxt.options.test) {
|
||||||
consola.log(
|
logger.log(
|
||||||
'🧪 Vite mode is experimental and some nuxt modules might be incompatible\n',
|
'🧪 Vite mode is experimental and some nuxt modules might be incompatible\n',
|
||||||
' If found a bug, please report via https://github.com/nuxt/vite/issues with a minimal reproduction.'
|
' If found a bug, please report via https://github.com/nuxt/framework/issues with a minimal reproduction.'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { createVuePlugin } from 'vite-plugin-vue2'
|
import { createVuePlugin } from 'vite-plugin-vue2'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import fse from 'fs-extra'
|
import fse from 'fs-extra'
|
||||||
import pDebounce from 'p-debounce'
|
import pDebounce from 'p-debounce'
|
||||||
import { bundleRequest } from '../../../vite/src/dev-bundler'
|
import { bundleRequest } from '../../../vite/src/dev-bundler'
|
||||||
@ -80,10 +80,10 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
// Production build
|
// Production build
|
||||||
if (!ctx.nuxt.options.dev) {
|
if (!ctx.nuxt.options.dev) {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
consola.info('Building server...')
|
logger.info('Building server...')
|
||||||
await vite.build(serverConfig)
|
await vite.build(serverConfig)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
consola.success(`Server built in ${Date.now() - start}ms`)
|
logger.success(`Server built in ${Date.now() - start}ms`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import { withoutLeadingSlash } from 'ufo'
|
import { withoutLeadingSlash } from 'ufo'
|
||||||
import { distDir } from '../dirs'
|
import { distDir } from '../dirs'
|
||||||
import { warmupViteServer } from '../../../vite/src/utils/warmup'
|
import { warmupViteServer } from '../../../vite/src/utils/warmup'
|
||||||
@ -95,8 +95,8 @@ async function bundle (nuxt: Nuxt, builder: any) {
|
|||||||
ctx.nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
|
ctx.nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
warmupViteServer(server, ['/.nuxt/entry.mjs']).then(() => {
|
warmupViteServer(server, ['/.nuxt/entry.mjs']).then(() => {
|
||||||
consola.info(`Vite warmed up in ${Date.now() - start}ms`)
|
logger.info(`Vite warmed up in ${Date.now() - start}ms`)
|
||||||
}).catch(consola.error)
|
}).catch(logger.error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ export * from './plugin'
|
|||||||
export * from './resolve'
|
export * from './resolve'
|
||||||
export * from './server'
|
export * from './server'
|
||||||
export * from './template'
|
export * from './template'
|
||||||
|
export * from './logger'
|
||||||
|
|
||||||
// Internal Utils
|
// Internal Utils
|
||||||
// TODO
|
// TODO
|
||||||
|
7
packages/kit/src/logger.ts
Normal file
7
packages/kit/src/logger.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import consola from 'consola'
|
||||||
|
|
||||||
|
export const logger = consola
|
||||||
|
|
||||||
|
export function useLogger (scope?: string) {
|
||||||
|
return scope ? logger.withScope(scope) : logger
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { parse, relative } from 'pathe'
|
import { parse, relative } from 'pathe'
|
||||||
import consola from 'consola'
|
|
||||||
import type { Nuxt, NuxtPluginTemplate, NuxtTemplate, ModuleContainer } from '@nuxt/schema'
|
import type { Nuxt, NuxtPluginTemplate, NuxtTemplate, ModuleContainer } from '@nuxt/schema'
|
||||||
|
import { logger } from '../logger'
|
||||||
import { chainFn } from '../internal/task'
|
import { chainFn } from '../internal/task'
|
||||||
import { addTemplate } from '../template'
|
import { addTemplate } from '../template'
|
||||||
import { addServerMiddleware } from '../server'
|
import { addServerMiddleware } from '../server'
|
||||||
@ -67,7 +67,7 @@ export function useModuleContainer (nuxt: Nuxt = useNuxt()): ModuleContainer {
|
|||||||
const layout = nuxt.options.layouts[layoutName]
|
const layout = nuxt.options.layouts[layoutName]
|
||||||
|
|
||||||
if (layout) {
|
if (layout) {
|
||||||
consola.warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`)
|
logger.warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`)
|
||||||
}
|
}
|
||||||
nuxt.options.layouts[layoutName] = `./${filename}`
|
nuxt.options.layouts[layoutName] = `./${filename}`
|
||||||
if (name === 'error') {
|
if (name === 'error') {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { promises as fsp } from 'fs'
|
import { promises as fsp } from 'fs'
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
import { applyDefaults } from 'untyped'
|
import { applyDefaults } from 'untyped'
|
||||||
import consola from 'consola'
|
|
||||||
import { dirname } from 'pathe'
|
import { dirname } from 'pathe'
|
||||||
import type { Nuxt, NuxtTemplate, NuxtModule, ModuleOptions, ModuleDefinition } from '@nuxt/schema'
|
import type { Nuxt, NuxtTemplate, NuxtModule, ModuleOptions, ModuleDefinition } from '@nuxt/schema'
|
||||||
|
import { logger } from '../logger'
|
||||||
import { useNuxt, nuxtCtx } from '../context'
|
import { useNuxt, nuxtCtx } from '../context'
|
||||||
import { isNuxt2, checkNuxtCompatibility } from '../compatibility'
|
import { isNuxt2, checkNuxtCompatibility } from '../compatibility'
|
||||||
import { templateUtils, compileTemplate } from '../internal/template'
|
import { templateUtils, compileTemplate } from '../internal/template'
|
||||||
@ -17,7 +17,7 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (definition: Mo
|
|||||||
if (typeof definition === 'function') {
|
if (typeof definition === 'function') {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
definition = definition(useNuxt())
|
definition = definition(useNuxt())
|
||||||
consola.warn('Module definition as function is deprecated and will be removed in the future versions', definition)
|
logger.warn('Module definition as function is deprecated and will be removed in the future versions', definition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize definition and meta
|
// Normalize definition and meta
|
||||||
@ -57,11 +57,11 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (definition: Mo
|
|||||||
nuxt.options._requiredModules[uniqueKey] = true
|
nuxt.options._requiredModules[uniqueKey] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check compatibility contraints
|
// Check compatibility constraints
|
||||||
if (definition.meta.compatibility) {
|
if (definition.meta.compatibility) {
|
||||||
const issues = await checkNuxtCompatibility(definition.meta.compatibility, nuxt)
|
const issues = await checkNuxtCompatibility(definition.meta.compatibility, nuxt)
|
||||||
if (issues.length) {
|
if (issues.length) {
|
||||||
consola.warn(`Module \`${definition.meta.name}\` is disabled due to incompatibility issues:\n${issues.toString()}`)
|
logger.warn(`Module \`${definition.meta.name}\` is disabled due to incompatibility issues:\n${issues.toString()}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { relative, resolve, join } from 'pathe'
|
import { relative, resolve, join } from 'pathe'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import * as rollup from 'rollup'
|
import * as rollup from 'rollup'
|
||||||
import fse from 'fs-extra'
|
import fse from 'fs-extra'
|
||||||
import { genDynamicImport } from 'knitwork'
|
import { genDynamicImport } from 'knitwork'
|
||||||
@ -10,7 +10,7 @@ import { NitroContext } from './context'
|
|||||||
import { scanMiddleware } from './server/middleware'
|
import { scanMiddleware } from './server/middleware'
|
||||||
|
|
||||||
export async function prepare (nitroContext: NitroContext) {
|
export async function prepare (nitroContext: NitroContext) {
|
||||||
consola.info(`Nitro preset is ${hl(nitroContext.preset)}`)
|
logger.info(`Nitro preset is ${hl(nitroContext.preset)}`)
|
||||||
|
|
||||||
await cleanupDir(nitroContext.output.dir)
|
await cleanupDir(nitroContext.output.dir)
|
||||||
|
|
||||||
@ -24,12 +24,12 @@ export async function prepare (nitroContext: NitroContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function cleanupDir (dir: string) {
|
async function cleanupDir (dir: string) {
|
||||||
consola.info('Cleaning up', prettyPath(dir))
|
logger.info('Cleaning up', prettyPath(dir))
|
||||||
await fse.emptyDir(dir)
|
await fse.emptyDir(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generate (nitroContext: NitroContext) {
|
export async function generate (nitroContext: NitroContext) {
|
||||||
consola.start('Generating public...')
|
logger.start('Generating public...')
|
||||||
|
|
||||||
await nitroContext._internal.hooks.callHook('nitro:generate', nitroContext)
|
await nitroContext._internal.hooks.callHook('nitro:generate', nitroContext)
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ export async function generate (nitroContext: NitroContext) {
|
|||||||
await fse.copy(clientDist, buildAssetsDir)
|
await fse.copy(clientDist, buildAssetsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
consola.success('Generated public ' + prettyPath(nitroContext.output.publicDir))
|
logger.success('Generated public ' + prettyPath(nitroContext.output.publicDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function build (nitroContext: NitroContext) {
|
export async function build (nitroContext: NitroContext) {
|
||||||
@ -96,13 +96,13 @@ async function _build (nitroContext: NitroContext) {
|
|||||||
nitroContext.scannedMiddleware = await scanMiddleware(nitroContext._nuxt.serverDir)
|
nitroContext.scannedMiddleware = await scanMiddleware(nitroContext._nuxt.serverDir)
|
||||||
await writeTypes(nitroContext)
|
await writeTypes(nitroContext)
|
||||||
|
|
||||||
consola.start('Building server...')
|
logger.start('Building server...')
|
||||||
const build = await rollup.rollup(nitroContext.rollupConfig).catch((error) => {
|
const build = await rollup.rollup(nitroContext.rollupConfig).catch((error) => {
|
||||||
consola.error('Rollup error: ' + error.message)
|
logger.error('Rollup error: ' + error.message)
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
|
|
||||||
consola.start('Writing server bundle...')
|
logger.start('Writing server bundle...')
|
||||||
await build.write(nitroContext.rollupConfig.output)
|
await build.write(nitroContext.rollupConfig.output)
|
||||||
|
|
||||||
const rewriteBuildPaths = (input: unknown, to: string) =>
|
const rewriteBuildPaths = (input: unknown, to: string) =>
|
||||||
@ -120,7 +120,7 @@ async function _build (nitroContext: NitroContext) {
|
|||||||
}
|
}
|
||||||
await writeFile(nitroConfigPath, JSON.stringify(buildInfo, null, 2))
|
await writeFile(nitroConfigPath, JSON.stringify(buildInfo, null, 2))
|
||||||
|
|
||||||
consola.success('Server built')
|
logger.success('Server built')
|
||||||
await printFSTree(nitroContext.output.serverDir)
|
await printFSTree(nitroContext.output.serverDir)
|
||||||
await nitroContext._internal.hooks.callHook('nitro:compiled', nitroContext)
|
await nitroContext._internal.hooks.callHook('nitro:compiled', nitroContext)
|
||||||
|
|
||||||
@ -128,10 +128,10 @@ async function _build (nitroContext: NitroContext) {
|
|||||||
const rOutDir = relative(process.cwd(), nitroContext.output.dir)
|
const rOutDir = relative(process.cwd(), nitroContext.output.dir)
|
||||||
if (nitroContext.commands.preview) {
|
if (nitroContext.commands.preview) {
|
||||||
// consola.info(`You can preview this build using \`${rewriteBuildPaths(nitroContext.commands.preview, rOutDir)}\``)
|
// consola.info(`You can preview this build using \`${rewriteBuildPaths(nitroContext.commands.preview, rOutDir)}\``)
|
||||||
consola.info('You can preview this build using `nuxi preview`')
|
logger.info('You can preview this build using `nuxi preview`')
|
||||||
}
|
}
|
||||||
if (nitroContext.commands.deploy) {
|
if (nitroContext.commands.deploy) {
|
||||||
consola.info(`You can deploy this build using \`${rewriteBuildPaths(nitroContext.commands.deploy, rOutDir)}\``)
|
logger.info(`You can deploy this build using \`${rewriteBuildPaths(nitroContext.commands.deploy, rOutDir)}\``)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -157,12 +157,12 @@ function startRollupWatcher (nitroContext: NitroContext) {
|
|||||||
// Finished building all bundles
|
// Finished building all bundles
|
||||||
case 'END':
|
case 'END':
|
||||||
nitroContext._internal.hooks.callHook('nitro:compiled', nitroContext)
|
nitroContext._internal.hooks.callHook('nitro:compiled', nitroContext)
|
||||||
consola.success('Nitro built', start ? `in ${Date.now() - start} ms` : '')
|
logger.success('Nitro built', start ? `in ${Date.now() - start} ms` : '')
|
||||||
return
|
return
|
||||||
|
|
||||||
// Encountered an error while bundling
|
// Encountered an error while bundling
|
||||||
case 'ERROR':
|
case 'ERROR':
|
||||||
consola.error('Rollup error: ' + event.error)
|
logger.error('Rollup error: ' + event.error)
|
||||||
// consola.error(event.error)
|
// consola.error(event.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { existsSync, promises as fsp } from 'fs'
|
import { existsSync, promises as fsp } from 'fs'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { genString } from 'knitwork'
|
import { genString } from 'knitwork'
|
||||||
import { extendPreset, prettyPath } from '../utils'
|
import { extendPreset, prettyPath } from '../utils'
|
||||||
@ -77,7 +77,7 @@ if ('serviceWorker' in navigator) {
|
|||||||
if (!existsSync(resolve(output.publicDir, '404.html'))) {
|
if (!existsSync(resolve(output.publicDir, '404.html'))) {
|
||||||
await fsp.writeFile(resolve(output.publicDir, '404.html'), html, 'utf8')
|
await fsp.writeFile(resolve(output.publicDir, '404.html'), html, 'utf8')
|
||||||
}
|
}
|
||||||
consola.info('Ready to deploy to static hosting:', prettyPath(output.publicDir as string))
|
logger.info('Ready to deploy to static hosting:', prettyPath(output.publicDir as string))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
|
|
||||||
import { writeTypes } from '../utils/prepare'
|
import { writeTypes } from '../utils/prepare'
|
||||||
import { loadKit } from '../utils/kit'
|
import { loadKit } from '../utils/kit'
|
||||||
import { clearDir } from '../utils/fs'
|
import { clearDir } from '../utils/fs'
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
"@vue/shared": "^3.2.31",
|
"@vue/shared": "^3.2.31",
|
||||||
"@vueuse/head": "^0.7.5",
|
"@vueuse/head": "^0.7.5",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"consola": "^2.15.3",
|
|
||||||
"cookie-es": "^0.5.0",
|
"cookie-es": "^0.5.0",
|
||||||
"defu": "^5.0.1",
|
"defu": "^5.0.1",
|
||||||
"destr": "^1.1.0",
|
"destr": "^1.1.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { createRequire } from 'module'
|
import { createRequire } from 'module'
|
||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import { isAbsolute, relative, resolve } from 'pathe'
|
import { isAbsolute, relative, resolve } from 'pathe'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import escapeRE from 'escape-string-regexp'
|
import escapeRE from 'escape-string-regexp'
|
||||||
@ -40,7 +40,7 @@ export const ImportProtectionPlugin = createUnplugin(function (options: ImportPr
|
|||||||
if (cache[id].has(pattern)) { continue }
|
if (cache[id].has(pattern)) { continue }
|
||||||
|
|
||||||
const relativeImporter = isAbsolute(importer) ? relative(options.rootDir, importer) : importer
|
const relativeImporter = isAbsolute(importer) ? relative(options.rootDir, importer) : importer
|
||||||
consola.error(warning || 'Invalid import', `[importing \`${id}\` from \`${relativeImporter}\`]`)
|
logger.error(warning || 'Invalid import', `[importing \`${id}\` from \`${relativeImporter}\`]`)
|
||||||
cache[id].set(pattern, true)
|
cache[id].set(pattern, true)
|
||||||
matched = true
|
matched = true
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ export default defineBuildConfig({
|
|||||||
'webpack-bundle-analyzer',
|
'webpack-bundle-analyzer',
|
||||||
'rollup-plugin-visualizer',
|
'rollup-plugin-visualizer',
|
||||||
'vite',
|
'vite',
|
||||||
|
'consola',
|
||||||
// Implicit
|
// Implicit
|
||||||
'@vue/compiler-core',
|
'@vue/compiler-core',
|
||||||
'@vue/shared'
|
'@vue/shared'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { join, resolve } from 'pathe'
|
import { join, resolve } from 'pathe'
|
||||||
import { isDevelopment } from 'std-env'
|
import { isDevelopment, isTest } from 'std-env'
|
||||||
import createRequire from 'create-require'
|
import createRequire from 'create-require'
|
||||||
import { pascalCase } from 'scule'
|
import { pascalCase } from 'scule'
|
||||||
import jiti from 'jiti'
|
import jiti from 'jiti'
|
||||||
@ -7,7 +7,7 @@ import defu from 'defu'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
* Extend nested configurations from multiple local or remoted sources
|
* Extend nested configurations from multiple local or remote sources
|
||||||
*
|
*
|
||||||
* Value should be either a string or array of strings pointing to source directories or config path relative to current config.
|
* Value should be either a string or array of strings pointing to source directories or config path relative to current config.
|
||||||
*
|
*
|
||||||
@ -738,5 +738,5 @@ export default {
|
|||||||
*/
|
*/
|
||||||
publicRuntimeConfig: {
|
publicRuntimeConfig: {
|
||||||
$resolve: (val: Record<string, any> = {}, get) => ({ ...val, app: defu(val.app, get('app')) })
|
$resolve: (val: Record<string, any> = {}, get) => ({ ...val, app: defu(val.app, get('app')) })
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,4 +58,4 @@ export interface NuxtApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type _TemplatePlugin = NuxtPlugin & NuxtTemplate
|
type _TemplatePlugin = NuxtPlugin & NuxtTemplate
|
||||||
export interface NuxtPluginTemplate extends _TemplatePlugin {}
|
export interface NuxtPluginTemplate extends _TemplatePlugin { }
|
||||||
|
@ -10,6 +10,7 @@ export function createTestContext (options: Partial<TestOptions>): TestContext {
|
|||||||
fixture: 'fixture',
|
fixture: 'fixture',
|
||||||
configFile: 'nuxt.config',
|
configFile: 'nuxt.config',
|
||||||
setupTimeout: 60000,
|
setupTimeout: 60000,
|
||||||
|
logLevel: 1,
|
||||||
server: options.browser,
|
server: options.browser,
|
||||||
build: options.browser || options.server,
|
build: options.browser || options.server,
|
||||||
nuxtConfig: {},
|
nuxtConfig: {},
|
||||||
|
@ -54,6 +54,8 @@ export async function loadFixture () {
|
|||||||
configFile: ctx.options.configFile
|
configFile: ctx.options.configFile
|
||||||
})
|
})
|
||||||
|
|
||||||
|
kit.logger.level = ctx.options.logLevel
|
||||||
|
|
||||||
await fsp.mkdir(ctx.nuxt.options.buildDir, { recursive: true })
|
await fsp.mkdir(ctx.nuxt.options.buildDir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export interface TestOptions {
|
|||||||
waitFor: number
|
waitFor: number
|
||||||
browser: boolean
|
browser: boolean
|
||||||
runner: TestRunner
|
runner: TestRunner
|
||||||
|
logLevel: number
|
||||||
browserOptions: {
|
browserOptions: {
|
||||||
type: 'chromium' | 'firefox' | 'webkit'
|
type: 'chromium' | 'firefox' | 'webkit'
|
||||||
launch?: LaunchOptions
|
launch?: LaunchOptions
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
"@vitejs/plugin-vue-jsx": "^1.3.7",
|
"@vitejs/plugin-vue-jsx": "^1.3.7",
|
||||||
"autoprefixer": "^10.4.2",
|
"autoprefixer": "^10.4.2",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"consola": "^2.15.3",
|
|
||||||
"defu": "^5.0.1",
|
"defu": "^5.0.1",
|
||||||
"esbuild": "^0.14.21",
|
"esbuild": "^0.14.21",
|
||||||
"escape-string-regexp": "^5.0.0",
|
"escape-string-regexp": "^5.0.0",
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import consola from 'consola'
|
|
||||||
import vuePlugin from '@vitejs/plugin-vue'
|
import vuePlugin from '@vitejs/plugin-vue'
|
||||||
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
||||||
import type { Connect } from 'vite'
|
import type { Connect } from 'vite'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
import { cacheDirPlugin } from './plugins/cache-dir'
|
||||||
import { analyzePlugin } from './plugins/analyze'
|
import { analyzePlugin } from './plugins/analyze'
|
||||||
@ -80,7 +79,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
await vite.build(clientConfig)
|
await vite.build(clientConfig)
|
||||||
await ctx.nuxt.callHook('build:resources', wpfs)
|
await ctx.nuxt.callHook('build:resources', wpfs)
|
||||||
consola.info(`Client built in ${Date.now() - start}ms`)
|
logger.info(`Client built in ${Date.now() - start}ms`)
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeManifest(ctx)
|
await writeManifest(ctx)
|
||||||
|
@ -2,10 +2,9 @@ import { join, resolve, normalize } from 'pathe'
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import vuePlugin from '@vitejs/plugin-vue'
|
import vuePlugin from '@vitejs/plugin-vue'
|
||||||
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
||||||
|
import { logger, resolveModule } from '@nuxt/kit'
|
||||||
import fse from 'fs-extra'
|
import fse from 'fs-extra'
|
||||||
import pDebounce from 'p-debounce'
|
import pDebounce from 'p-debounce'
|
||||||
import consola from 'consola'
|
|
||||||
import { resolveModule } from '@nuxt/kit'
|
|
||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
import { ViteBuildContext, ViteOptions } from './vite'
|
import { ViteBuildContext, ViteOptions } from './vite'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -117,10 +116,10 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
// Production build
|
// Production build
|
||||||
if (!ctx.nuxt.options.dev) {
|
if (!ctx.nuxt.options.dev) {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
consola.info('Building server...')
|
logger.info('Building server...')
|
||||||
await vite.build(serverConfig)
|
await vite.build(serverConfig)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
consola.success(`Server built in ${Date.now() - start}ms`)
|
logger.success(`Server built in ${Date.now() - start}ms`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
// Have CSS in the manifest to prevent FOUC on dev SSR
|
// Have CSS in the manifest to prevent FOUC on dev SSR
|
||||||
await writeManifest(ctx, ids.filter(isCSS).map(i => i.slice(1)))
|
await writeManifest(ctx, ids.filter(isCSS).map(i => i.slice(1)))
|
||||||
const time = (Date.now() - start)
|
const time = (Date.now() - start)
|
||||||
consola.success(`Vite server built in ${time}ms`)
|
logger.success(`Vite server built in ${time}ms`)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
}
|
}
|
||||||
const doBuild = pDebounce(_doBuild, 100)
|
const doBuild = pDebounce(_doBuild, 100)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
import type { ViteDevServer } from 'vite'
|
import type { ViteDevServer } from 'vite'
|
||||||
|
|
||||||
export async function warmupViteServer (server: ViteDevServer, entries: string[]) {
|
export async function warmupViteServer (server: ViteDevServer, entries: string[]) {
|
||||||
@ -10,7 +10,7 @@ export async function warmupViteServer (server: ViteDevServer, entries: string[]
|
|||||||
try {
|
try {
|
||||||
await server.transformRequest(url)
|
await server.transformRequest(url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
consola.debug('Warmup for %s failed with: %s', url, e)
|
logger.debug('Warmup for %s failed with: %s', url, e)
|
||||||
}
|
}
|
||||||
const deps = Array.from(server.moduleGraph.urlToModuleMap.get(url)?.importedModules || [])
|
const deps = Array.from(server.moduleGraph.urlToModuleMap.get(url)?.importedModules || [])
|
||||||
await Promise.all(deps.map(m => warmup(m.url)))
|
await Promise.all(deps.map(m => warmup(m.url)))
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import type { InlineConfig, SSROptions } from 'vite'
|
import type { InlineConfig, SSROptions } from 'vite'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
import type { Options } from '@vitejs/plugin-vue'
|
import type { Options } from '@vitejs/plugin-vue'
|
||||||
import { sanitizeFilePath } from 'mlly'
|
import { sanitizeFilePath } from 'mlly'
|
||||||
import { joinURL, withoutLeadingSlash } from 'ufo'
|
import { joinURL, withoutLeadingSlash } from 'ufo'
|
||||||
@ -126,9 +126,9 @@ export async function bundle (nuxt: Nuxt) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
warmupViteServer(server, ['/entry.mjs']).then(() => {
|
warmupViteServer(server, ['/entry.mjs'])
|
||||||
consola.info(`Vite warmed up in ${Date.now() - start}ms`)
|
.then(() => logger.info(`Vite warmed up in ${Date.now() - start}ms`))
|
||||||
}).catch(consola.error)
|
.catch(logger.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
await buildClient(ctx)
|
await buildClient(ctx)
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
"@vue/babel-preset-jsx": "^1.2.4",
|
"@vue/babel-preset-jsx": "^1.2.4",
|
||||||
"autoprefixer": "^10.4.2",
|
"autoprefixer": "^10.4.2",
|
||||||
"babel-loader": "^8.2.3",
|
"babel-loader": "^8.2.3",
|
||||||
"consola": "^2.15.3",
|
|
||||||
"css-loader": "^6.6.0",
|
"css-loader": "^6.6.0",
|
||||||
"css-minimizer-webpack-plugin": "^3.4.1",
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
||||||
"cssnano": "^5.0.17",
|
"cssnano": "^5.0.17",
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
|
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
|
|
||||||
export const validate = (compiler) => {
|
export const validate = (compiler) => {
|
||||||
if (compiler.options.target !== 'node') {
|
if (compiler.options.target !== 'node') {
|
||||||
consola.warn('webpack config `target` should be "node".')
|
logger.warn('webpack config `target` should be "node".')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compiler.options.externals) {
|
if (!compiler.options.externals) {
|
||||||
consola.info(
|
logger.info(
|
||||||
'It is recommended to externalize dependencies in the server build for ' +
|
'It is recommended to externalize dependencies in the server build for ' +
|
||||||
'better build performance.'
|
'better build performance.'
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { resolve, normalize } from 'pathe'
|
import { resolve, normalize } from 'pathe'
|
||||||
import TimeFixPlugin from 'time-fix-plugin'
|
import TimeFixPlugin from 'time-fix-plugin'
|
||||||
import WebpackBar from 'webpackbar'
|
import WebpackBar from 'webpackbar'
|
||||||
import consola from 'consola'
|
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
||||||
import escapeRegExp from 'escape-string-regexp'
|
import escapeRegExp from 'escape-string-regexp'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
@ -93,7 +93,7 @@ function basePlugins (ctx: WebpackConfigContext) {
|
|||||||
if (state.hasErrors) {
|
if (state.hasErrors) {
|
||||||
nuxt.callHook('bundler:error')
|
nuxt.callHook('bundler:error')
|
||||||
} else {
|
} else {
|
||||||
consola.success(`${state.name} ${state.message}`)
|
logger.success(`${state.name} ${state.message}`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
allDone: () => {
|
allDone: () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import consola from 'consola'
|
|
||||||
import { cloneDeep } from 'lodash-es'
|
import { cloneDeep } from 'lodash-es'
|
||||||
import type { Configuration } from 'webpack'
|
import type { Configuration } from 'webpack'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
|
|
||||||
export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ }
|
export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ }
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ export function fileName (ctx: WebpackConfigContext, key: string) {
|
|||||||
if (typeof fileName === 'string' && options.dev) {
|
if (typeof fileName === 'string' && options.dev) {
|
||||||
const hash = /\[(chunkhash|contenthash|hash)(?::(\d+))?]/.exec(fileName)
|
const hash = /\[(chunkhash|contenthash|hash)(?::(\d+))?]/.exec(fileName)
|
||||||
if (hash) {
|
if (hash) {
|
||||||
consola.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`)
|
logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ export function getWebpackConfig (ctx: WebpackConfigContext): Configuration {
|
|||||||
const { devtool } = extendedConfig
|
const { devtool } = extendedConfig
|
||||||
if (typeof devtool === 'string' && pragma.test(devtool)) {
|
if (typeof devtool === 'string' && pragma.test(devtool)) {
|
||||||
extendedConfig.devtool = devtool.replace(pragma, '')
|
extendedConfig.devtool = devtool.replace(pragma, '')
|
||||||
consola.warn(`devtool has been normalized to ${extendedConfig.devtool} as webpack documented value`)
|
logger.warn(`devtool has been normalized to ${extendedConfig.devtool} as webpack documented value`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return extendedConfig
|
return extendedConfig
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
import { logger, requireModule } from '@nuxt/kit'
|
||||||
import { createCommonJS } from 'mlly'
|
import { createCommonJS } from 'mlly'
|
||||||
import { defaults, merge, cloneDeep } from 'lodash-es'
|
import { defaults, merge, cloneDeep } from 'lodash-es'
|
||||||
import createResolver from 'postcss-import-resolver'
|
import createResolver from 'postcss-import-resolver'
|
||||||
import { requireModule } from '@nuxt/kit'
|
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
|
|
||||||
const isPureObject = obj => obj !== null && !Array.isArray(obj) && typeof obj === 'object'
|
const isPureObject = obj => obj !== null && !Array.isArray(obj) && typeof obj === 'object'
|
||||||
@ -34,7 +33,7 @@ function postcssConfigFileWarning () {
|
|||||||
if (_postcssConfigFileWarningShown) {
|
if (_postcssConfigFileWarningShown) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
consola.warn('Please use `build.postcss` in your nuxt.config.js instead of an external config file. Support for such files will be removed in Nuxt 3 as they remove all defaults set by Nuxt and can cause severe problems with features like alias resolving inside your CSS.')
|
logger.warn('Please use `build.postcss` in your nuxt.config.js instead of an external config file. Support for such files will be removed in Nuxt 3 as they remove all defaults set by Nuxt and can cause severe problems with features like alias resolving inside your CSS.')
|
||||||
_postcssConfigFileWarningShown = true
|
_postcssConfigFileWarningShown = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ import Glob from 'glob'
|
|||||||
import webpackDevMiddleware from 'webpack-dev-middleware'
|
import webpackDevMiddleware from 'webpack-dev-middleware'
|
||||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||||
import VirtualModulesPlugin from 'webpack-virtual-modules'
|
import VirtualModulesPlugin from 'webpack-virtual-modules'
|
||||||
import consola from 'consola'
|
import { logger } from '@nuxt/kit'
|
||||||
|
|
||||||
import type { Compiler, Watching } from 'webpack'
|
import type { Compiler, Watching } from 'webpack'
|
||||||
import type { Context as WebpackDevMiddlewareContext, Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
import type { Context as WebpackDevMiddlewareContext, Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
||||||
import type { MiddlewareOptions as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware'
|
import type { MiddlewareOptions as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware'
|
||||||
@ -96,7 +95,7 @@ class WebpackBundler {
|
|||||||
// Check styleResource existence
|
// Check styleResource existence
|
||||||
const { styleResources } = this.nuxt.options.build
|
const { styleResources } = this.nuxt.options.build
|
||||||
if (styleResources && Object.keys(styleResources).length) {
|
if (styleResources && Object.keys(styleResources).length) {
|
||||||
consola.warn(
|
logger.warn(
|
||||||
'Using styleResources without the @nuxtjs/style-resources is not suggested and can lead to severe performance issues.',
|
'Using styleResources without the @nuxtjs/style-resources is not suggested and can lead to severe performance issues.',
|
||||||
'Please use https://github.com/nuxt-community/style-resources-module'
|
'Please use https://github.com/nuxt-community/style-resources-module'
|
||||||
)
|
)
|
||||||
@ -204,7 +203,7 @@ class WebpackBundler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async webpackDev (compiler: Compiler) {
|
async webpackDev (compiler: Compiler) {
|
||||||
consola.debug('Creating webpack middleware...')
|
logger.debug('Creating webpack middleware...')
|
||||||
|
|
||||||
const { name } = compiler.options
|
const { name } = compiler.options
|
||||||
const buildOptions = this.nuxt.options.build
|
const buildOptions = this.nuxt.options.build
|
||||||
|
@ -2652,7 +2652,6 @@ __metadata:
|
|||||||
"@vue/composition-api": ^1.4.6
|
"@vue/composition-api": ^1.4.6
|
||||||
"@vueuse/head": ^0.7.5
|
"@vueuse/head": ^0.7.5
|
||||||
acorn: ^8.7.0
|
acorn: ^8.7.0
|
||||||
consola: ^2.15.3
|
|
||||||
cookie-es: ^0.5.0
|
cookie-es: ^0.5.0
|
||||||
defu: ^5.0.1
|
defu: ^5.0.1
|
||||||
destr: ^1.1.0
|
destr: ^1.1.0
|
||||||
@ -3359,7 +3358,6 @@ __metadata:
|
|||||||
"@vitejs/plugin-vue-jsx": ^1.3.7
|
"@vitejs/plugin-vue-jsx": ^1.3.7
|
||||||
autoprefixer: ^10.4.2
|
autoprefixer: ^10.4.2
|
||||||
chokidar: ^3.5.3
|
chokidar: ^3.5.3
|
||||||
consola: ^2.15.3
|
|
||||||
defu: ^5.0.1
|
defu: ^5.0.1
|
||||||
esbuild: ^0.14.21
|
esbuild: ^0.14.21
|
||||||
escape-string-regexp: ^5.0.0
|
escape-string-regexp: ^5.0.0
|
||||||
@ -3476,7 +3474,6 @@ __metadata:
|
|||||||
"@vue/babel-preset-jsx": ^1.2.4
|
"@vue/babel-preset-jsx": ^1.2.4
|
||||||
autoprefixer: ^10.4.2
|
autoprefixer: ^10.4.2
|
||||||
babel-loader: ^8.2.3
|
babel-loader: ^8.2.3
|
||||||
consola: ^2.15.3
|
|
||||||
css-loader: ^6.6.0
|
css-loader: ^6.6.0
|
||||||
css-minimizer-webpack-plugin: ^3.4.1
|
css-minimizer-webpack-plugin: ^3.4.1
|
||||||
cssnano: ^5.0.17
|
cssnano: ^5.0.17
|
||||||
@ -15385,7 +15382,6 @@ __metadata:
|
|||||||
"@vue/shared": ^3.2.31
|
"@vue/shared": ^3.2.31
|
||||||
"@vueuse/head": ^0.7.5
|
"@vueuse/head": ^0.7.5
|
||||||
chokidar: ^3.5.3
|
chokidar: ^3.5.3
|
||||||
consola: ^2.15.3
|
|
||||||
cookie-es: ^0.5.0
|
cookie-es: ^0.5.0
|
||||||
defu: ^5.0.1
|
defu: ^5.0.1
|
||||||
destr: ^1.1.0
|
destr: ^1.1.0
|
||||||
|
Loading…
Reference in New Issue
Block a user