diff --git a/packages/kit/package.json b/packages/kit/package.json index baa95c9917..f216a275d1 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -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": { diff --git a/packages/kit/src/config/schema/build.ts b/packages/kit/src/config/schema/build.ts index 1f069dd3e9..b31302a5b8 100644 --- a/packages/kit/src/config/schema/build.ts +++ b/packages/kit/src/config/schema/build.ts @@ -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]' diff --git a/packages/kit/src/types/hooks.ts b/packages/kit/src/types/hooks.ts index b9efa9c52f..654114eed6 100644 --- a/packages/kit/src/types/hooks.ts +++ b/packages/kit/src/types/hooks.ts @@ -1,6 +1,6 @@ import { Nuxt } from './nuxt' -export type NuxtHook = (arg1: Arg1, ...args: any) => Promise | void +export type NuxtHook = (arg1?: Arg1, ...args: any) => Promise | void export interface NuxtHooks { [key: string]: NuxtHook diff --git a/packages/nuxt3/src/nitro.ts b/packages/nuxt3/src/nitro.ts index 00a0bb12ca..f9692987a5 100644 --- a/packages/nuxt3/src/nitro.ts +++ b/packages/nuxt3/src/nitro.ts @@ -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')) diff --git a/packages/nuxt3/src/vite/vite.ts b/packages/nuxt3/src/vite/vite.ts index 1bed4856e8..c9eeec8317 100644 --- a/packages/nuxt3/src/vite/vite.ts +++ b/packages/nuxt3/src/vite/vite.ts @@ -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' diff --git a/packages/nuxt3/src/webpack/presets/babel.ts b/packages/nuxt3/src/webpack/presets/babel.ts index ea9d334e30..0bb0e18a2a 100644 --- a/packages/nuxt3/src/webpack/presets/babel.ts +++ b/packages/nuxt3/src/webpack/presets/babel.ts @@ -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) } } diff --git a/packages/nuxt3/src/webpack/presets/base.ts b/packages/nuxt3/src/webpack/presets/base.ts index 1a5680d67b..a3e52d5b1b 100644 --- a/packages/nuxt3/src/webpack/presets/base.ts +++ b/packages/nuxt3/src/webpack/presets/base.ts @@ -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, diff --git a/packages/nuxt3/src/webpack/presets/style.ts b/packages/nuxt3/src/webpack/presets/style.ts index e562ac568e..5417cd52e0 100644 --- a/packages/nuxt3/src/webpack/presets/style.ts +++ b/packages/nuxt3/src/webpack/presets/style.ts @@ -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 } } diff --git a/packages/nuxt3/src/webpack/utils/config.ts b/packages/nuxt3/src/webpack/utils/config.ts index f477de6a59..1e13948ba4 100644 --- a/packages/nuxt3/src/webpack/utils/config.ts +++ b/packages/nuxt3/src/webpack/utils/config.ts @@ -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{ } diff --git a/packages/nuxt3/src/webpack/webpack.ts b/packages/nuxt3/src/webpack/webpack.ts index f39f62dd48..9aae1ad6d8 100644 --- a/packages/nuxt3/src/webpack/webpack.ts +++ b/packages/nuxt3/src/webpack/webpack.ts @@ -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' } } diff --git a/yarn.lock b/yarn.lock index 451a495e81..fce6c68496 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"