Skip to content

Commit

Permalink
chore: better unbuild hook for copy and removal
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
  • Loading branch information
nekomeowww committed Jul 10, 2024
1 parent 95ae906 commit d31f9ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { exec } from 'node:child_process'
import { promisify } from 'node:util'
import { defineBuildConfig } from 'unbuild'
import builtins from 'builtin-modules'

const execAsync = promisify(exec)

export default defineBuildConfig({
outDir: './dist',
sourcemap: true,
Expand All @@ -20,11 +24,6 @@ export default defineBuildConfig({
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
// UnoCSS
'@iconify/utils/lib/loader/fs',
'@iconify/utils/lib/loader/install-pkg',
'@iconify/utils/lib/loader/node-loader',
'@iconify/utils/lib/loader/node-loaders',
// Builtins
...builtins,
],
Expand All @@ -44,4 +43,14 @@ export default defineBuildConfig({
// by esbuild
inlineDependencies: true,
},
hooks: {
'build:before': async () => {
await execAsync('rm -rf ./main.js')
await execAsync('rm -rf ./main.js.map')
},
'build:done': async () => {
await execAsync('cp ./dist/main.js ./main.js')
await execAsync('cp ./dist/main.js.map ./main.js.map')
},
},
})
3 changes: 3 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ dictionaries: []
words:
- antfu
- codemirror
- collab
- lezer
- nolebase
- Nólëbase
- ofetch
- unocss
- vueuse
ignoreWords: []
import: []
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"dist"
],
"scripts": {
"cleanup": "rm -rf ./main.js && rm -rf ./main.js.map",
"build": "unbuild && pnpm run cleanup && pnpm run copy",
"copy": "cp ./dist/main.js ./main.js && cp ./dist/main.js.map ./main.js.map",
"build": "unbuild",
"lint": "eslint --cache ."
},
"devDependencies": {
Expand Down

0 comments on commit d31f9ac

Please sign in to comment.