fix(vite): fix dist dir resolution (#6215)

This commit is contained in:
Anthony Fu 2022-07-29 20:33:24 +08:00 committed by GitHub
parent 5a042cd69b
commit 6b20d9eff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -9,12 +9,10 @@ import { joinURL, withLeadingSlash, withoutLeadingSlash, withTrailingSlash } fro
import escapeRE from 'escape-string-regexp' import escapeRE from 'escape-string-regexp'
import defu from 'defu' import defu from 'defu'
import { cacheDirPlugin } from './plugins/cache-dir' import { cacheDirPlugin } from './plugins/cache-dir'
import { analyzePlugin } from './plugins/analyze'
import { wpfs } from './utils/wpfs' import { wpfs } from './utils/wpfs'
import type { ViteBuildContext, ViteOptions } from './vite' import type { ViteBuildContext, ViteOptions } from './vite'
import { writeManifest } from './manifest' import { writeManifest } from './manifest'
import { devStyleSSRPlugin } from './plugins/dev-ssr-css' import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
import { viteNodePlugin } from './vite-node'
export async function buildClient (ctx: ViteBuildContext) { export async function buildClient (ctx: ViteBuildContext) {
const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, { const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
@ -58,7 +56,9 @@ export async function buildClient (ctx: ViteBuildContext) {
rootDir: ctx.nuxt.options.rootDir, rootDir: ctx.nuxt.options.rootDir,
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir) buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
}), }),
viteNodePlugin(ctx) ctx.nuxt.options.experimental.viteNode
? await import('./vite-node').then(r => r.viteNodePlugin(ctx))
: undefined
], ],
appType: 'custom', appType: 'custom',
server: { server: {
@ -87,7 +87,7 @@ export async function buildClient (ctx: ViteBuildContext) {
// Add analyze plugin if needed // Add analyze plugin if needed
if (ctx.nuxt.options.build.analyze) { if (ctx.nuxt.options.build.analyze) {
clientConfig.plugins.push(...analyzePlugin(ctx)) clientConfig.plugins.push(...await import('./plugins/analyze').then(r => r.analyzePlugin(ctx)))
} }
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false }) await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })

View File

@ -1,5 +1,7 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'pathe' import { dirname, resolve } from 'pathe'
export const distDir = dirname(fileURLToPath(import.meta.url)) let _distDir = dirname(fileURLToPath(import.meta.url))
if (_distDir.endsWith('chunks')) { _distDir = dirname(_distDir) }
export const distDir = _distDir
export const pkgDir = resolve(distDir, '..') export const pkgDir = resolve(distDir, '..')