mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
chore: fix type and imports
This commit is contained in:
parent
6fb4028850
commit
4829d89b17
@ -25,7 +25,7 @@
|
||||
"std-env": "^2.3.0",
|
||||
"ufo": "^0.6.10",
|
||||
"unctx": "^0.0.3",
|
||||
"untyped": "^0.2.2",
|
||||
"untyped": "^0.2.4",
|
||||
"upath": "^2.0.1"
|
||||
},
|
||||
"build": {
|
||||
|
@ -31,18 +31,19 @@ export default {
|
||||
video: ({ isDev }) => isDev ? '[path][name].[ext]' : 'videos/[name].[contenthash:7].[ext]'
|
||||
},
|
||||
loaders: {
|
||||
// $resolve: (val, get) => {
|
||||
// const styleLoaders = [
|
||||
// 'css', 'cssModules', 'less',
|
||||
// 'sass', 'scss', 'stylus', 'vueStyle'
|
||||
// ]
|
||||
// for (const name of styleLoaders) {
|
||||
// const loader = val[name]
|
||||
// if (loader && loader.sourceMap === undefined) {
|
||||
// loader.sourceMap = Boolean(get('build.cssSourceMap'))
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
$resolve: (val, get) => {
|
||||
const styleLoaders = [
|
||||
'css', 'cssModules', 'less',
|
||||
'sass', 'scss', 'stylus', 'vueStyle'
|
||||
]
|
||||
for (const name of styleLoaders) {
|
||||
const loader = val[name]
|
||||
if (loader && loader.sourceMap === undefined) {
|
||||
loader.sourceMap = Boolean(get('build.cssSourceMap'))
|
||||
}
|
||||
}
|
||||
return val
|
||||
},
|
||||
file: { esModule: false },
|
||||
fontUrl: { esModule: false, limit: 1000 },
|
||||
imgUrl: { esModule: false, limit: 1000 },
|
||||
@ -56,8 +57,12 @@ export default {
|
||||
embed: 'src'
|
||||
}
|
||||
},
|
||||
css: { esModule: false },
|
||||
css: {
|
||||
importLoaders: 0,
|
||||
esModule: false
|
||||
},
|
||||
cssModules: {
|
||||
importLoaders: 0,
|
||||
esModule: false,
|
||||
modules: {
|
||||
localIdentName: '[local]_[hash:base64:5]'
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Nuxt } from './nuxt'
|
||||
|
||||
export type NuxtHook<Arg1 = any> = (arg1: Arg1, ...args: any) => Promise<void> | void
|
||||
export type NuxtHook<Arg1 = any> = (arg1?: Arg1, ...args: any) => Promise<void> | void
|
||||
|
||||
export interface NuxtHooks {
|
||||
[key: string]: NuxtHook
|
||||
|
@ -9,9 +9,11 @@ export function initNitro (nuxt: Nuxt) {
|
||||
nuxt.server = createDevServer(nitroDevContext)
|
||||
|
||||
// Connect hooks
|
||||
// @ts-ignore
|
||||
nuxt.hooks.addHooks(nitroContext.nuxtHooks)
|
||||
nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close'))
|
||||
|
||||
// @ts-ignore
|
||||
nuxt.hooks.addHooks(nitroDevContext.nuxtHooks)
|
||||
nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close'))
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { resolve } from 'path'
|
||||
import { Nuxt } from 'sr..c/core'
|
||||
import type { Nuxt } from '@nuxt/kit'
|
||||
import { mkdirp, writeFile } from 'fs-extra'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import consola from 'consola'
|
||||
|
@ -44,7 +44,7 @@ export function babel (ctx: WebpackConfigContext) {
|
||||
...options.build.terser as any
|
||||
})
|
||||
|
||||
config.plugins.push(terser as WebpackPluginInstance)
|
||||
config.plugins.push(terser as any)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import consola from 'consola'
|
||||
import { DefinePlugin, Configuration } from 'webpack'
|
||||
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
|
||||
import escapeRegExp from 'lodash/escapeRegExp'
|
||||
import { isUrl, urlJoin, TARGETS } from '@nuxt/kit'
|
||||
import { hasProtocol, joinURL } from 'ufo'
|
||||
import WarningIgnorePlugin from '../plugins/warning-ignore'
|
||||
import { WebpackConfigContext, applyPresets, fileName } from '../utils/config'
|
||||
|
||||
@ -82,6 +82,7 @@ function basePlugins (ctx: WebpackConfigContext) {
|
||||
reporters: ['stats'],
|
||||
stats: !ctx.isDev,
|
||||
reporter: {
|
||||
// @ts-ignore
|
||||
change: (_, { shortPath }) => {
|
||||
if (!ctx.isServer) {
|
||||
nuxt.callHook('bundler:change', shortPath)
|
||||
@ -185,9 +186,9 @@ function getOutput (ctx: WebpackConfigContext): Configuration['output'] {
|
||||
path: resolve(options.buildDir, 'dist', ctx.isServer ? 'server' : 'client'),
|
||||
filename: fileName(ctx, 'app'),
|
||||
chunkFilename: fileName(ctx, 'chunk'),
|
||||
publicPath: isUrl(options.build.publicPath)
|
||||
publicPath: hasProtocol(options.build.publicPath, true)
|
||||
? options.build.publicPath
|
||||
: urlJoin(options.router.base, options.build.publicPath)
|
||||
: joinURL(options.router.base, options.build.publicPath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +213,7 @@ function getEnv (ctx: WebpackConfigContext) {
|
||||
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
|
||||
'process.mode': JSON.stringify(ctx.config.mode),
|
||||
'process.dev': options.dev,
|
||||
'process.static': options.target === TARGETS.static,
|
||||
'process.static': options.target === 'static',
|
||||
'process.target': JSON.stringify(options.target),
|
||||
'process.env.VUE_ENV': JSON.stringify(ctx.name),
|
||||
'process.browser': ctx.isClient,
|
||||
|
@ -1,7 +1,6 @@
|
||||
import path from 'path'
|
||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
||||
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
|
||||
import { wrapArray } from '@nuxt/kit'
|
||||
import { fileName, WebpackConfigContext, applyPresets } from '../utils/config'
|
||||
|
||||
export function style (ctx: WebpackConfigContext) {
|
||||
@ -17,7 +16,7 @@ function minimizer (ctx: WebpackConfigContext) {
|
||||
|
||||
if (options.build.optimizeCSS && Array.isArray(config.optimization.minimizer)) {
|
||||
config.optimization.minimizer.push(new CssMinimizerPlugin({
|
||||
...options.build.optimizeCSS
|
||||
...options.build.optimizeCSS as any
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -30,7 +29,7 @@ function extractCSS (ctx: WebpackConfigContext) {
|
||||
config.plugins.push(new MiniCssExtractPlugin({
|
||||
filename: fileName(ctx, 'css'),
|
||||
chunkFilename: fileName(ctx, 'css'),
|
||||
...(options.build.extractCSS as object)
|
||||
...(options.build.extractCSS as any)
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -129,7 +128,7 @@ function createStyleResourcesLoaderRule (styleLang, styleResources, rootDir) {
|
||||
return {
|
||||
loader: 'style-resources-loader',
|
||||
options: {
|
||||
patterns: wrapArray(styleResources[styleLang]).map(p => path.resolve(rootDir, p)),
|
||||
patterns: Array.from(styleResources[styleLang]).map(p => path.resolve(rootDir, p as string)),
|
||||
...styleResources.options
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import consola from 'consola'
|
||||
import cloneDeep from 'lodash/cloneDeep'
|
||||
import { Configuration } from 'webpack'
|
||||
import { Nuxt } from '../../../core'
|
||||
import type { Nuxt } from '@nuxt/kit'
|
||||
|
||||
export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ }
|
||||
|
||||
|
@ -10,8 +10,7 @@ import type { Compiler, Watching } from 'webpack'
|
||||
import type { Context as WebpackDevMiddlewareContext, Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
|
||||
import type { MiddlewareOptions as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware'
|
||||
|
||||
import { TARGETS, parallel, sequence, wrapArray } from '@nuxt/kit'
|
||||
import { Nuxt } from '../../core'
|
||||
import type { Nuxt } from '@nuxt/kit'
|
||||
import { createMFS } from './utils/mfs'
|
||||
import { client, server } from './configs'
|
||||
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
|
||||
@ -87,8 +86,8 @@ class WebpackBundler {
|
||||
'Please use https://github.com/nuxt-community/style-resources-module'
|
||||
)
|
||||
for (const ext of Object.keys(styleResources)) {
|
||||
await Promise.all(wrapArray(styleResources[ext]).map(async (p) => {
|
||||
const styleResourceFiles = await glob(path.resolve(this.nuxt.options.rootDir, p))
|
||||
await Promise.all(Array.from(styleResources[ext]).map(async (p) => {
|
||||
const styleResourceFiles = await glob(path.resolve(this.nuxt.options.rootDir, p as string))
|
||||
|
||||
if (!styleResourceFiles || styleResourceFiles.length === 0) {
|
||||
throw new Error(`Style Resource not found: ${p}`)
|
||||
@ -110,9 +109,13 @@ class WebpackBundler {
|
||||
})
|
||||
|
||||
// Start Builds
|
||||
const runner = options.dev ? parallel : sequence
|
||||
|
||||
await runner(this.compilers, compiler => this.webpackCompile(compiler))
|
||||
if (options.dev) {
|
||||
return Promise.all(this.compilers.map(c => this.webpackCompile(c)))
|
||||
} else {
|
||||
for (const c of this.compilers) {
|
||||
await this.webpackCompile(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async webpackCompile (compiler) {
|
||||
@ -264,7 +267,7 @@ class WebpackBundler {
|
||||
}
|
||||
|
||||
forGenerate () {
|
||||
this.nuxt.options.target = TARGETS.static
|
||||
this.nuxt.options.target = 'static'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10750,10 +10750,10 @@ unset-value@^1.0.0:
|
||||
has-value "^0.3.1"
|
||||
isobject "^3.0.0"
|
||||
|
||||
untyped@^0.2.2:
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.2.tgz#b8c83d2e8f890cd45108495929bb5574b274fa1a"
|
||||
integrity sha512-AZPhUm/dr/2mnK1mwE67FuV3hbKers34Vp0b8xz26b9JwPg62bvVJGHyWU2rC05acW6tO6OZHfqE5m1J/JjtPg==
|
||||
untyped@^0.2.4:
|
||||
version "0.2.4"
|
||||
resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.4.tgz#03170e9d70812cd2844d7070c625fbd657f463d3"
|
||||
integrity sha512-nLrY9MB0+iBs/A3mfwmc1MTT1eJOvGhH08oIKI4iMtd2qkTyh6gDDeI4Lx89gJe9SbkFXwvX04n4XbG2m4kshg==
|
||||
|
||||
upath@^2.0.1:
|
||||
version "2.0.1"
|
||||
|
Loading…
Reference in New Issue
Block a user