提交 71312b81 编写于 作者: fxy060608's avatar fxy060608

fix: outDir

上级 bf26249a
......@@ -38,7 +38,7 @@ cli
cli
.command('')
.alias('serve')
.alias('dev')
.option('--host [host]', `[string] specify hostname`)
.option('--port <port>', `[number] specify port`)
.option('--https', `[boolean] use TLS + HTTP/2`)
......@@ -50,7 +50,7 @@ cli
`[boolean] force the optimizer to ignore the cache and re-bundle`
)
.action(async (options: CliOptions & ServerOptions) => {
initEnv(options)
initEnv('dev', options)
try {
await (options.ssr ? createSSRServer(options) : createServer(options))
} catch (e) {
......@@ -81,16 +81,20 @@ cli
.option('--ssrManifest', `[boolean] emit ssr manifest json`)
.option(
'--emptyOutDir',
`[boolean] force empty outDir when it's outside of root`
`[boolean] force empty outDir when it's outside of root`,
{
default: true,
}
)
.option('-m, --mode <mode>', `[string] set env mode`)
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
.action(async (options: CliOptions & BuildOptions) => {
initEnv(options)
initEnv('build', options)
try {
await (options.ssr && options.platform === 'h5'
? buildSSR(options)
: build(options))
console.log(` DONE Build complete.`)
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error during build:\n${e.stack}`)
......
......@@ -14,20 +14,38 @@ export const PLATFORMS = [
'quickapp-webview-union',
]
export function initEnv(options: CliOptions) {
export function initEnv(type: 'dev' | 'build', options: CliOptions) {
if (type === 'dev') {
process.env.NODE_ENV = 'development'
} else if (type === 'build') {
if ((options as BuildOptions).watch) {
process.env.NODE_ENV = 'development'
} else {
process.env.NODE_ENV = 'production'
}
}
process.env.UNI_CLI_CONTEXT = process.cwd() // TODO HBuilderX
process.env.UNI_PLATFORM = options.platform as UniApp.PLATFORM
process.env.VITE_ROOT_DIR = process.env.UNI_INPUT_DIR || process.cwd()
process.env.UNI_INPUT_DIR =
process.env.UNI_INPUT_DIR || path.resolve(process.cwd(), 'src')
process.env.UNI_OUTPUT_DIR =
(options as BuildOptions).outDir ||
process.env.UNI_OUTPUT_DIR ||
path.resolve(process.cwd(), 'dist')
process.env.UNI_PLATFORM = options.platform as UniApp.PLATFORM
if (process.env.UNI_OUTPUT_DIR) {
;(options as BuildOptions).outDir = process.env.UNI_OUTPUT_DIR
} else {
if (!(options as BuildOptions).outDir) {
;(options as BuildOptions).outDir = path.join(
'dist',
process.env.NODE_ENV === 'production' ? 'build' : 'dev',
process.env.UNI_PLATFORM
)
}
process.env.UNI_OUTPUT_DIR = (options as BuildOptions).outDir!
}
}
export function cleanOptions(options: CliOptions) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册