mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): don't copy publicDir
files to _nuxt
(#2135)
This commit is contained in:
parent
84b6201dea
commit
c5eed5e12b
@ -4,7 +4,7 @@ import * as rollup from 'rollup'
|
||||
import fse from 'fs-extra'
|
||||
import { printFSTree } from './utils/tree'
|
||||
import { getRollupConfig } from './rollup/config'
|
||||
import { hl, prettyPath, serializeTemplate, writeFile, isDirectory } from './utils'
|
||||
import { hl, prettyPath, serializeTemplate, writeFile, isDirectory, readDirRecursively } from './utils'
|
||||
import { NitroContext } from './context'
|
||||
import { scanMiddleware } from './server/middleware'
|
||||
|
||||
@ -30,14 +30,20 @@ async function cleanupDir (dir: string) {
|
||||
export async function generate (nitroContext: NitroContext) {
|
||||
consola.start('Generating public...')
|
||||
|
||||
const clientDist = resolve(nitroContext._nuxt.buildDir, 'dist/client')
|
||||
if (await isDirectory(clientDist)) {
|
||||
await fse.copy(clientDist, join(nitroContext.output.publicDir, nitroContext._nuxt.publicPath))
|
||||
const publicDir = nitroContext._nuxt.publicDir
|
||||
let publicFiles: string[] = []
|
||||
if (await isDirectory(publicDir)) {
|
||||
publicFiles = readDirRecursively(publicDir).map(r => r.replace(publicDir, ''))
|
||||
await fse.copy(publicDir, nitroContext.output.publicDir)
|
||||
}
|
||||
|
||||
const publicDir = nitroContext._nuxt.publicDir
|
||||
if (await isDirectory(publicDir)) {
|
||||
await fse.copy(publicDir, nitroContext.output.publicDir)
|
||||
const clientDist = resolve(nitroContext._nuxt.buildDir, 'dist/client')
|
||||
if (await isDirectory(clientDist)) {
|
||||
await fse.copy(clientDist, join(nitroContext.output.publicDir, nitroContext._nuxt.publicPath), {
|
||||
// TODO: Workaround vite's issue that duplicates public files
|
||||
// https://github.com/nuxt/framework/issues/1192
|
||||
filter: src => !publicFiles.includes(src.replace(clientDist, ''))
|
||||
})
|
||||
}
|
||||
|
||||
consola.success('Generated public ' + prettyPath(nitroContext.output.publicDir))
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createRequire } from 'module'
|
||||
import { relative, dirname, resolve } from 'pathe'
|
||||
import { relative, dirname, join, resolve } from 'pathe'
|
||||
import fse from 'fs-extra'
|
||||
import jiti from 'jiti'
|
||||
import defu from 'defu'
|
||||
@ -148,3 +148,11 @@ export function readPackageJson (
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export function readDirRecursively (dir: string) {
|
||||
return fse.readdirSync(dir).reduce((files, file) => {
|
||||
const name = join(dir, file)
|
||||
const isDirectory = fse.statSync(name).isDirectory()
|
||||
return isDirectory ? [...files, ...readDirRecursively(name)] : [...files, name]
|
||||
}, [])
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ export async function bundle (nuxt: Nuxt) {
|
||||
}
|
||||
},
|
||||
base: nuxt.options.build.publicPath,
|
||||
publicDir: resolve(nuxt.options.srcDir, nuxt.options.dir.public),
|
||||
// TODO: move to kit schema when it exists
|
||||
vue: {
|
||||
isProduction: !nuxt.options.dev,
|
||||
|
Loading…
Reference in New Issue
Block a user