Skip to content

Commit

Permalink
feat: suuport viteMode close #332
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Jul 5, 2024
1 parent 25b20e1 commit 1bdfff9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ yargs
vite: {
desc: 'Start application by vite'
},
viteMode: {
desc: 'same like vite start --mode'
},
port: {
desc: 'Setting application server port, default is 3000'
},
Expand Down Expand Up @@ -153,6 +156,9 @@ yargs
vite: {
desc: 'Build application by vite'
},
viteMode: {
desc: 'same like vite build --mode'
},
legacy: {
desc: 'Close default rollup manulChunks setting in vite mode'
},
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const handleEnv = async (argv: Argv) => {
if (argv.nominify) {
process.env.NOMINIFY = '1'
}
if (argv.viteMode) {
process.env.VITEMODE = argv.viteMode
}

process.env.SERVER_PORT = argv.port ? String(argv.port) : '3000'
if (argv.vite) {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-react/src/tools/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ const viteStart = async () => {
}
const viteBuild = async () => {
await build({ ...clientConfig, mode: 'production' })
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

const viteBuildClient = async () => {
await build({ ...clientConfig, mode: 'production' }).catch(_ => { })
await build({ ...clientConfig, mode: process.env.VITEMODE ?? 'production' }).catch(_ => { })
}
const viteBuildServer = async () => {
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

export {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-react18/src/tools/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ const viteStart = async () => {
}
const viteBuild = async () => {
await build({ ...clientConfig, mode: 'production' })
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

const viteBuildClient = async () => {
await build({ ...clientConfig, mode: 'production' }).catch(_ => { })
await build({ ...clientConfig, mode: process.env.VITEMODE ?? 'production' }).catch(_ => { })
}
const viteBuildServer = async () => {
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

export {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/tools/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const viteStart = async () => {
const viteBuild = async () => {
const build: typeof BuildType = (await import('vite')).build
await build({ ...clientConfig, mode: 'production' })
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

export {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue3/src/tools/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ const viteStart = async () => {
}
const viteBuild = async () => {
await build({ ...clientConfig, mode: 'production' })
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

const viteBuildClient = async () => {
await build({ ...clientConfig, mode: 'production' }).catch(_ => { })
await build({ ...clientConfig, mode: process.env.VITEMODE ?? 'production' }).catch(_ => { })
}
const viteBuildServer = async () => {
await build({ ...serverConfig, mode: 'production' })
await build({ ...serverConfig, mode: process.env.VITEMODE ?? 'production' })
}

export {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/yargs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type Argv = Arguments<{
bc?: boolean
bcp?: string
sourcemap?: string
viteMode?: string
}>
2 changes: 1 addition & 1 deletion packages/utils/src/server/vite/config-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const commonConfig = (): UserConfig => {
const lessOptions = css?.().loaderOptions?.less?.lessOptions ? css?.().loaderOptions?.less?.lessOptions : css?.().loaderOptions?.less
return {
root: cwd,
mode: 'development',
mode: process.env.VITEMODE ?? 'development',
...(optimize ? { logLevel: 'slient' } : {}),
server: {
middlewareMode: 'ssr' as SSR,
Expand Down

0 comments on commit 1bdfff9

Please sign in to comment.