chore: fix type and imports

This commit is contained in:
Pooya Parsa 2021-04-02 21:38:11 +02:00
parent 6fb4028850
commit 4829d89b17
11 changed files with 48 additions and 38 deletions

View File

@ -25,7 +25,7 @@
"std-env": "^2.3.0", "std-env": "^2.3.0",
"ufo": "^0.6.10", "ufo": "^0.6.10",
"unctx": "^0.0.3", "unctx": "^0.0.3",
"untyped": "^0.2.2", "untyped": "^0.2.4",
"upath": "^2.0.1" "upath": "^2.0.1"
}, },
"build": { "build": {

View File

@ -31,18 +31,19 @@ export default {
video: ({ isDev }) => isDev ? '[path][name].[ext]' : 'videos/[name].[contenthash:7].[ext]' video: ({ isDev }) => isDev ? '[path][name].[ext]' : 'videos/[name].[contenthash:7].[ext]'
}, },
loaders: { loaders: {
// $resolve: (val, get) => { $resolve: (val, get) => {
// const styleLoaders = [ const styleLoaders = [
// 'css', 'cssModules', 'less', 'css', 'cssModules', 'less',
// 'sass', 'scss', 'stylus', 'vueStyle' 'sass', 'scss', 'stylus', 'vueStyle'
// ] ]
// for (const name of styleLoaders) { for (const name of styleLoaders) {
// const loader = val[name] const loader = val[name]
// if (loader && loader.sourceMap === undefined) { if (loader && loader.sourceMap === undefined) {
// loader.sourceMap = Boolean(get('build.cssSourceMap')) loader.sourceMap = Boolean(get('build.cssSourceMap'))
// } }
// } }
// }, return val
},
file: { esModule: false }, file: { esModule: false },
fontUrl: { esModule: false, limit: 1000 }, fontUrl: { esModule: false, limit: 1000 },
imgUrl: { esModule: false, limit: 1000 }, imgUrl: { esModule: false, limit: 1000 },
@ -56,8 +57,12 @@ export default {
embed: 'src' embed: 'src'
} }
}, },
css: { esModule: false }, css: {
importLoaders: 0,
esModule: false
},
cssModules: { cssModules: {
importLoaders: 0,
esModule: false, esModule: false,
modules: { modules: {
localIdentName: '[local]_[hash:base64:5]' localIdentName: '[local]_[hash:base64:5]'

View File

@ -1,6 +1,6 @@
import { Nuxt } from './nuxt' 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 { export interface NuxtHooks {
[key: string]: NuxtHook [key: string]: NuxtHook

View File

@ -9,9 +9,11 @@ export function initNitro (nuxt: Nuxt) {
nuxt.server = createDevServer(nitroDevContext) nuxt.server = createDevServer(nitroDevContext)
// Connect hooks // Connect hooks
// @ts-ignore
nuxt.hooks.addHooks(nitroContext.nuxtHooks) nuxt.hooks.addHooks(nitroContext.nuxtHooks)
nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close')) nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close'))
// @ts-ignore
nuxt.hooks.addHooks(nitroDevContext.nuxtHooks) nuxt.hooks.addHooks(nitroDevContext.nuxtHooks)
nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close')) nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close'))

View File

@ -1,5 +1,5 @@
import { resolve } from 'path' import { resolve } from 'path'
import { Nuxt } from 'sr..c/core' import type { Nuxt } from '@nuxt/kit'
import { mkdirp, writeFile } from 'fs-extra' import { mkdirp, writeFile } from 'fs-extra'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import consola from 'consola' import consola from 'consola'

View File

@ -44,7 +44,7 @@ export function babel (ctx: WebpackConfigContext) {
...options.build.terser as any ...options.build.terser as any
}) })
config.plugins.push(terser as WebpackPluginInstance) config.plugins.push(terser as any)
} }
} }

View File

@ -5,7 +5,7 @@ import consola from 'consola'
import { DefinePlugin, Configuration } from 'webpack' import { DefinePlugin, Configuration } from 'webpack'
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin' import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
import escapeRegExp from 'lodash/escapeRegExp' import escapeRegExp from 'lodash/escapeRegExp'
import { isUrl, urlJoin, TARGETS } from '@nuxt/kit' import { hasProtocol, joinURL } from 'ufo'
import WarningIgnorePlugin from '../plugins/warning-ignore' import WarningIgnorePlugin from '../plugins/warning-ignore'
import { WebpackConfigContext, applyPresets, fileName } from '../utils/config' import { WebpackConfigContext, applyPresets, fileName } from '../utils/config'
@ -82,6 +82,7 @@ function basePlugins (ctx: WebpackConfigContext) {
reporters: ['stats'], reporters: ['stats'],
stats: !ctx.isDev, stats: !ctx.isDev,
reporter: { reporter: {
// @ts-ignore
change: (_, { shortPath }) => { change: (_, { shortPath }) => {
if (!ctx.isServer) { if (!ctx.isServer) {
nuxt.callHook('bundler:change', shortPath) nuxt.callHook('bundler:change', shortPath)
@ -185,9 +186,9 @@ function getOutput (ctx: WebpackConfigContext): Configuration['output'] {
path: resolve(options.buildDir, 'dist', ctx.isServer ? 'server' : 'client'), path: resolve(options.buildDir, 'dist', ctx.isServer ? 'server' : 'client'),
filename: fileName(ctx, 'app'), filename: fileName(ctx, 'app'),
chunkFilename: fileName(ctx, 'chunk'), chunkFilename: fileName(ctx, 'chunk'),
publicPath: isUrl(options.build.publicPath) publicPath: hasProtocol(options.build.publicPath, true)
? options.build.publicPath ? 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.env.NODE_ENV': JSON.stringify(ctx.config.mode),
'process.mode': JSON.stringify(ctx.config.mode), 'process.mode': JSON.stringify(ctx.config.mode),
'process.dev': options.dev, 'process.dev': options.dev,
'process.static': options.target === TARGETS.static, 'process.static': options.target === 'static',
'process.target': JSON.stringify(options.target), 'process.target': JSON.stringify(options.target),
'process.env.VUE_ENV': JSON.stringify(ctx.name), 'process.env.VUE_ENV': JSON.stringify(ctx.name),
'process.browser': ctx.isClient, 'process.browser': ctx.isClient,

View File

@ -1,7 +1,6 @@
import path from 'path' import path from 'path'
import MiniCssExtractPlugin from 'mini-css-extract-plugin' import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin' import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import { wrapArray } from '@nuxt/kit'
import { fileName, WebpackConfigContext, applyPresets } from '../utils/config' import { fileName, WebpackConfigContext, applyPresets } from '../utils/config'
export function style (ctx: WebpackConfigContext) { export function style (ctx: WebpackConfigContext) {
@ -17,7 +16,7 @@ function minimizer (ctx: WebpackConfigContext) {
if (options.build.optimizeCSS && Array.isArray(config.optimization.minimizer)) { if (options.build.optimizeCSS && Array.isArray(config.optimization.minimizer)) {
config.optimization.minimizer.push(new CssMinimizerPlugin({ 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({ config.plugins.push(new MiniCssExtractPlugin({
filename: fileName(ctx, 'css'), filename: fileName(ctx, 'css'),
chunkFilename: 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 { return {
loader: 'style-resources-loader', loader: 'style-resources-loader',
options: { 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 ...styleResources.options
} }
} }

View File

@ -1,7 +1,7 @@
import consola from 'consola' import consola from 'consola'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import { Configuration } from 'webpack' import { Configuration } from 'webpack'
import { Nuxt } from '../../../core' import type { Nuxt } from '@nuxt/kit'
export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ } export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ }

View File

@ -10,8 +10,7 @@ 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'
import { TARGETS, parallel, sequence, wrapArray } from '@nuxt/kit' import type { Nuxt } from '@nuxt/kit'
import { Nuxt } from '../../core'
import { createMFS } from './utils/mfs' import { createMFS } from './utils/mfs'
import { client, server } from './configs' import { client, server } from './configs'
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config' import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
@ -87,8 +86,8 @@ class WebpackBundler {
'Please use https://github.com/nuxt-community/style-resources-module' 'Please use https://github.com/nuxt-community/style-resources-module'
) )
for (const ext of Object.keys(styleResources)) { for (const ext of Object.keys(styleResources)) {
await Promise.all(wrapArray(styleResources[ext]).map(async (p) => { await Promise.all(Array.from(styleResources[ext]).map(async (p) => {
const styleResourceFiles = await glob(path.resolve(this.nuxt.options.rootDir, p)) const styleResourceFiles = await glob(path.resolve(this.nuxt.options.rootDir, p as string))
if (!styleResourceFiles || styleResourceFiles.length === 0) { if (!styleResourceFiles || styleResourceFiles.length === 0) {
throw new Error(`Style Resource not found: ${p}`) throw new Error(`Style Resource not found: ${p}`)
@ -110,9 +109,13 @@ class WebpackBundler {
}) })
// Start Builds // Start Builds
const runner = options.dev ? parallel : sequence if (options.dev) {
return Promise.all(this.compilers.map(c => this.webpackCompile(c)))
await runner(this.compilers, compiler => this.webpackCompile(compiler)) } else {
for (const c of this.compilers) {
await this.webpackCompile(c)
}
}
} }
async webpackCompile (compiler) { async webpackCompile (compiler) {
@ -264,7 +267,7 @@ class WebpackBundler {
} }
forGenerate () { forGenerate () {
this.nuxt.options.target = TARGETS.static this.nuxt.options.target = 'static'
} }
} }

View File

@ -10750,10 +10750,10 @@ unset-value@^1.0.0:
has-value "^0.3.1" has-value "^0.3.1"
isobject "^3.0.0" isobject "^3.0.0"
untyped@^0.2.2: untyped@^0.2.4:
version "0.2.2" version "0.2.4"
resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.2.tgz#b8c83d2e8f890cd45108495929bb5574b274fa1a" resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.4.tgz#03170e9d70812cd2844d7070c625fbd657f463d3"
integrity sha512-AZPhUm/dr/2mnK1mwE67FuV3hbKers34Vp0b8xz26b9JwPg62bvVJGHyWU2rC05acW6tO6OZHfqE5m1J/JjtPg== integrity sha512-nLrY9MB0+iBs/A3mfwmc1MTT1eJOvGhH08oIKI4iMtd2qkTyh6gDDeI4Lx89gJe9SbkFXwvX04n4XbG2m4kshg==
upath@^2.0.1: upath@^2.0.1:
version "2.0.1" version "2.0.1"