mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat: generate public (dist/)
This commit is contained in:
parent
425941d1b4
commit
0245bd65de
@ -5,7 +5,7 @@ import Hookable from 'hookable'
|
|||||||
import prettyBytes from 'pretty-bytes'
|
import prettyBytes from 'pretty-bytes'
|
||||||
import gzipSize from 'gzip-size'
|
import gzipSize from 'gzip-size'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import { copy, emptyDir, existsSync } from 'fs-extra'
|
import { copy, emptyDir, existsSync, mkdirp } from 'fs-extra'
|
||||||
import { getRollupConfig } from './rollup/config'
|
import { getRollupConfig } from './rollup/config'
|
||||||
import { getTargetConfig } from './config'
|
import { getTargetConfig } from './config'
|
||||||
import { hl, prettyPath, renderTemplate, compileTemplateToJS } from './utils'
|
import { hl, prettyPath, renderTemplate, compileTemplateToJS } from './utils'
|
||||||
@ -39,13 +39,6 @@ export async function build (baseConfig, target) {
|
|||||||
consola.info('Compiled', prettyPath(dstPath))
|
consola.info('Compiled', prettyPath(dstPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.copyAssets) {
|
|
||||||
const publicDir = typeof config.copyAssets === 'string' ? config.copyAssets : 'public'
|
|
||||||
const dst = resolve(config.outDir, publicDir, '_nuxt')
|
|
||||||
await copy(resolve(config.buildDir, 'dist/client'), dst)
|
|
||||||
consola.info('Copied public assets to', prettyPath(dst))
|
|
||||||
}
|
|
||||||
|
|
||||||
await hooks.callHook('done', config)
|
await hooks.callHook('done', config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,3 +56,18 @@ export function ensureDist (baseConfig) {
|
|||||||
consola.success('Using existing nuxt build from', prettyPath(baseConfig.buildDir))
|
consola.success('Using existing nuxt build from', prettyPath(baseConfig.buildDir))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function generatePublic (baseConfig) {
|
||||||
|
await emptyDir(baseConfig.publicDir)
|
||||||
|
await mkdirp(baseConfig.publicDir)
|
||||||
|
|
||||||
|
await copy(
|
||||||
|
baseConfig.staticDir,
|
||||||
|
baseConfig.publicDir
|
||||||
|
)
|
||||||
|
|
||||||
|
await copy(
|
||||||
|
resolve(baseConfig.buildDir, 'dist/client'),
|
||||||
|
resolve(baseConfig.publicDir, '_nuxt')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { build, compileHTMLTemplate, ensureDist } from './build'
|
import { build, compileHTMLTemplate, ensureDist, generatePublic } from './build'
|
||||||
import { getBaseConfig } from './config'
|
import { getBaseConfig } from './config'
|
||||||
|
|
||||||
export async function runCLI () {
|
export async function runCLI () {
|
||||||
@ -14,6 +14,9 @@ export async function runCLI () {
|
|||||||
// Compile html template
|
// Compile html template
|
||||||
await compileHTMLTemplate(baseConfig)
|
await compileHTMLTemplate(baseConfig)
|
||||||
|
|
||||||
|
// Generate public dir
|
||||||
|
await generatePublic(baseConfig)
|
||||||
|
|
||||||
// Bundle for each target
|
// Bundle for each target
|
||||||
for (const target of baseConfig.targets) {
|
for (const target of baseConfig.targets) {
|
||||||
if (baseConfig.target && target.target !== baseConfig.target) {
|
if (baseConfig.target && target.target !== baseConfig.target) {
|
||||||
|
@ -6,6 +6,8 @@ export function getBaseConfig (rootDir) {
|
|||||||
let baseConfig = {
|
let baseConfig = {
|
||||||
rootDir,
|
rootDir,
|
||||||
buildDir: '',
|
buildDir: '',
|
||||||
|
publicDir: '',
|
||||||
|
staticDir: '',
|
||||||
targets: [],
|
targets: [],
|
||||||
templates: [],
|
templates: [],
|
||||||
nuxt: 2,
|
nuxt: 2,
|
||||||
@ -24,6 +26,8 @@ export function getBaseConfig (rootDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
baseConfig.buildDir = resolve(baseConfig.rootDir, baseConfig.buildDir || '.nuxt')
|
baseConfig.buildDir = resolve(baseConfig.rootDir, baseConfig.buildDir || '.nuxt')
|
||||||
|
baseConfig.publicDir = resolve(baseConfig.rootDir, baseConfig.publicDir || 'dist')
|
||||||
|
baseConfig.staticDir = resolve(baseConfig.rootDir, baseConfig.staticDir || 'static')
|
||||||
|
|
||||||
baseConfig.targets = baseConfig.targets.map(t => typeof t === 'string' ? { target: t } : t)
|
baseConfig.targets = baseConfig.targets.map(t => typeof t === 'string' ? { target: t } : t)
|
||||||
if (baseConfig.target && !baseConfig.targets.find(t => t.target === baseConfig.target)) {
|
if (baseConfig.target && !baseConfig.targets.find(t => t.target === baseConfig.target)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user