Skip to content

Commit 3ed6bb1

Browse files
committed
feat(tsx): replace nodemon with tsx
1 parent 5b83675 commit 3ed6bb1

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

dev.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'node:path'
2+
import { readdirSync, statSync } from 'node:fs'
3+
import { build } from 'esbuild'
4+
import nodemon from 'nodemon'
5+
6+
const getFilesRecursively = (dir: string) => {
7+
const fileArray = []
8+
const files = readdirSync(dir)
9+
files.forEach((file) => {
10+
const filePath = path.join(dir, file)
11+
if (statSync(filePath).isDirectory()) {
12+
getFilesRecursively(filePath)
13+
} else {
14+
fileArray.push(filePath)
15+
}
16+
})
17+
return fileArray.filter((file) => file.endsWith('.ts'))
18+
}
19+
20+
;(async () => {
21+
const builder = await build({
22+
entryPoints: getFilesRecursively('src'),
23+
logLevel: 'info',
24+
outdir: 'dist',
25+
platform: 'node',
26+
format: 'cjs',
27+
incremental: true
28+
})
29+
nodemon('-w src -x "dist"')
30+
.on('start', function () {
31+
console.log('App has started')
32+
builder.rebuild()
33+
})
34+
.on('quit', function () {
35+
console.log('App has quit')
36+
process.exit()
37+
})
38+
.on('restart', function (files) {
39+
console.log('App restarted due to: ', files)
40+
})
41+
})()

esbuild.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ build({
2828
logLevel: 'info',
2929
outdir: env === 'dev' ? 'dist' : 'build',
3030
bundle: env === 'dev' ? false : true,
31+
minify: env === 'dev' ? false : true,
3132
platform: 'node',
3233
format: 'cjs',
34+
sourcemap: true,
3335
plugins:
3436
env === 'dev' ? [] : [esbuildPluginPino({ transports: ['pino-pretty'] })]
3537
})

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.1",
44
"scripts": {
55
"prepare": "husky install",
6-
"dev": "nodemon",
6+
"dev": "tsx watch src",
77
"build": "rm -rf build && node esbuild.js",
88
"format": "prettier --write 'src/**/*.{js,ts,json,md}'",
99
"lint": "prettier --check 'src/**/*.{js,ts,json,md}' && eslint --ignore-path .gitignore .",

pnpm-lock.yaml

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const fastify = Fastify({
1515
}
1616
}
1717
})
18-
1918
fastify.register(autoLoad, {
2019
dir: join(__dirname, 'plugins')
2120
})

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"esModuleInterop": true,
34
"outDir": "./dist"
45
}
56
}

0 commit comments

Comments
 (0)