Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing out bun with NX/TSC/Vite #12

Merged
merged 12 commits into from
Feb 26, 2024
17 changes: 5 additions & 12 deletions .github/actions/install-workspace/action.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# .github/actions/setup-node/action.yml
name: 'install workspace'
description: 'Set up Node.js environment and check out code'
inputs:
node-version-file:
description: 'Path to Node version file'
default: '.nvmrc'
description: 'Set up Bun and install packages'
runs:
using: 'composite'
steps:
- name: setup node
uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v1
with:
node-version-file: ${{ inputs.node-version-file }}
cache: 'npm'
cache-dependency-path: 'package-lock.json'
bun-version: latest

- name: npm ci
run: npm ci --audit=false --fund=false
- name: bun install
run: bun install --silent
shell: bash
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
- name: install workspace
uses: ./.github/actions/install-workspace

- name: npm run build
run: npm run build
- name: bun run build
run: bun run build

test:
runs-on: ubuntu-latest
Expand All @@ -24,8 +24,8 @@ jobs:
- name: install workspace
uses: ./.github/actions/install-workspace

- name: npm test
run: npm test
- name: bun run test
run: bun run test

lint:
runs-on: ubuntu-latest
Expand All @@ -36,8 +36,8 @@ jobs:
- name: install workspace
uses: ./.github/actions/install-workspace

- name: npm run lint
run: npm run lint
- name: bun run lint
run: bun run lint

dockerize:
name: dockerize
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM node:21-alpine
FROM imbios/bun-node:latest-21-slim

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FROM imbios/bun-node:latest-21-slim
FROM oven/bun:1

Now you are running it in actual bun (vite etc) you shouldn't need node here anymore

WORKDIR /usr/src/app

COPY . ./

RUN npm ci

RUN npx nx run-many -t build -p koa-server react-app
RUN bun install --silent
RUN bunx nx run-many -t build -p koa-server react-app

ENV PORT=8080
EXPOSE 8080
CMD ["node", "./apps/koa-server/dist/server.js"]
CMD ["bun", "./apps/koa-server/dist/server.js"]
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ It is what @bhouston considers best practice in January 2024.

## Features

- Bun runtime for maximum speed.
- Mono-repository using NPM workspaces
- TypeScript for type safety
- ES Modules for fast builds
Expand All @@ -31,25 +32,25 @@ It is what @bhouston considers best practice in January 2024.
## Getting Started

1. Clone this repository
2. Run `npm install`
2. Run `bun install`

### Tests

1. Run `npm run test` to run all jest tests
1. Run `bun run test` to run all jest tests

### Continuous Dev Build

1. Run `npm run watch` to start the hot reload development server & build watchers
1. Run `bun run watch` to start the hot reload development server & build watchers

### Optimized Production Build

1. Run `npm run build` to build the source
1. Run `bun run build` to build the source

### Run the webserver (no reload)

1. Run `npx koa-server` to start the webserver
2. Open the link that appears in the console in your browser
1. Run `bunx koa-server` to start the webserver
2. Open `http://localhost:8000` in your browser

### Command Line

1. Run `npx cmdline-app` to run the CLI example
1. Run `bunx cmdline-app` to run the CLI example
2 changes: 1 addition & 1 deletion apps/koa-server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"targets": {
"watch": {
"options": {
"commands": ["tsc --watch", "nodemon dist/server.js"]
"commands": ["bunx tsc --watch", "bunx nodemon dist/server.js"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read comment below i think you could change this to the following

Suggested change
"commands": ["bunx tsc --watch", "bunx nodemon dist/server.js"]
"commands": ["bun run --watch server.ts"]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thx!

}
},
"build": {},
Expand Down
4 changes: 2 additions & 2 deletions apps/react-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"targets": {
"watch": {
"options": {
"commands": ["vite"]
"commands": ["bunx vite"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"commands": ["bunx vite"]
"commands": ["bunx --bun vite"]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adopted this! Thanks!

}
},
"build": {
"options": {
"commands": ["tsc", "vite build"]
"commands": ["bunx tsc", "bunx vite build"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using bunx vite will basically run vite in node and not bun. Same with TSC here. You need force bun with --bun
`
``suggestion
"commands": ["bunx --bun tsc", "bunx --bun vite build"]


bun also has bulit in support for typescript compling so you dont need to run TSC. Whats the reasoning for it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! thx!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jordan-Hall regarding:

"bun also has bulit in support for typescript compling so you dont need to run TSC. Whats the reasoning for it?"

I want to publish reusable libraries for others from some of my projects. Thus I want to transpire to *.js that is non-bundled, non-minified for easy reuse, tree shaking, etc.

I guess you'd recommend that I use https://bun.sh/docs/bundler? I guess that can be used for libraries and not just end user React apps?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct working on getting this to work on nx-bun but you can use cli for it

bun build ./index.tsx --outdir ./out

}
},
"lint": {},
Expand Down
Binary file added bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"outputs": ["{projectRoot}/dist"],
"options": {
"cwd": "{projectRoot}",
"commands": ["tsc --watch"],
"commands": ["bunx tsc --watch"],
"parallel": true
}
},
Expand All @@ -34,7 +34,7 @@
"outputs": ["{projectRoot}/dist"],
"options": {
"cwd": "{projectRoot}",
"commands": ["tsc"]
"commands": ["bunx tsc"]
},
"cache": true
},
Expand All @@ -54,7 +54,7 @@
"inputs": ["default"],
"options": {
"cwd": "{projectRoot}",
"command": "prettier \"src/**/*.{js,jsx,css,md,html,ts,tsx,json,yaml}\" --check"
"command": "bunx prettier \"src/**/*.{js,jsx,css,md,html,ts,tsx,json,yaml}\" --check"
},
"cache": true
},
Expand All @@ -65,7 +65,7 @@
"outputs": [],
"options": {
"cwd": "{projectRoot}",
"command": "node --experimental-vm-modules --no-warnings ../../node_modules/jest/bin/jest.js"
"command": "bun --experimental-vm-modules --no-warnings ../../node_modules/jest/bin/jest.js"
},
"cache": true
}
Expand Down
Loading
Loading