Skip to content

Commit

Permalink
build(client): use shell instead of vite plugin (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 authored Dec 21, 2023
1 parent 8453523 commit 2f6abc3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node": ">=v14.21.3"
},
"scripts": {
"build": "nr build:lib && vite build",
"build": "tsx ./scripts/pre-build.ts && (nr build:lib & vite build)",
"build:lib": "vite build --config vite.lib.config.ts",
"stub": "nr stub:lib && vite build --watch",
"stub:lib": "vite build --config vite.lib.config.ts --watch"
Expand Down
15 changes: 15 additions & 0 deletions packages/client/scripts/pre-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import fse from 'fs-extra'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

async function run() {
;['../../browser-extension/client', '../../electron/client', '../../vite/dist/client'].forEach((dir) => {
const absoluteDir = resolve(__dirname, dir)
if (fse.existsSync(absoluteDir))
fse.removeSync(absoluteDir)
})
}

await run()
8 changes: 0 additions & 8 deletions packages/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export default defineConfig(mergeConfig(baseConfig, {
// copy
const clientFile = resolve(__dirname, './dist')

// Removed `browser-extension` and `electron` on `build:lib`
// Remove `vite/dist/client` on building
;['../vite/dist/client'].forEach((dir) => {
const absoluteDir = resolve(__dirname, dir)
if (fse.existsSync(absoluteDir))
fse.removeSync(absoluteDir)
})

;['../browser-extension/client', '../electron/client', '../vite/dist/client'].forEach((dir) => {
fse.copySync(clientFile, resolve(__dirname, dir))
})
Expand Down
5 changes: 1 addition & 4 deletions packages/client/vite.lib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default defineConfig(mergeConfig(baseConfig, {
;['../browser-extension/client', '../electron/client'].forEach((dir) => {
// NOTE: remember the order of `build:lib` and `build`,
// if change the order, rmSync must set in `build` stage
const absoluteDir = resolve(__dirname, dir)
if (fse.existsSync(absoluteDir))
fse.removeSync(absoluteDir)
fse.copySync(clientFile, absoluteDir)
fse.copySync(clientFile, resolve(__dirname, dir))
})
},
},
Expand Down

0 comments on commit 2f6abc3

Please sign in to comment.