Skip to content

Commit 3dfce4c

Browse files
Add bundler and build process (#16)
* Setup rollup for bundling the library * feat(minification): minify the output bundle using terser use terser plugin in rollup to minify the generated UMD bundle * feat(ci): add a build job in ci execute the build process in ci and upload artifacts * fix(ci): remove commitlint job from PR commits modify commitlint job to run only for push and not on PR and issues
1 parent 7377c19 commit 3dfce4c

File tree

6 files changed

+214
-7
lines changed

6 files changed

+214
-7
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ jobs:
4141
if: github.event_name == 'push'
4242
run: npx commitlint --last --verbose
4343

44-
- name: Validate PR commits with commitlint
45-
if: github.event_name == 'pull_request'
46-
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
47-
4844
lint:
45+
needs: commitlint
4946
runs-on: ubuntu-latest
5047

5148
steps:
@@ -70,6 +67,7 @@ jobs:
7067
run: npm run lint
7168

7269
test:
70+
needs: lint
7371
runs-on: ubuntu-latest
7472

7573
steps:
@@ -92,3 +90,33 @@ jobs:
9290

9391
- name: Run test suites
9492
run: npm run test
93+
94+
build:
95+
needs: test
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Clone repo
99+
uses: actions/checkout@v4
100+
101+
- name: Install NodeJS
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: 22.12.0
105+
106+
- name: Cache npm dependencies
107+
uses: actions/cache@v4
108+
with:
109+
path: ~/.npm
110+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
111+
112+
- name: Install dependencies
113+
run: npm ci
114+
115+
- name: Build project
116+
run: npm run build
117+
118+
- name: Upload build artifact
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: build
122+
path: dist

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
dist/

package-lock.json

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"prepare": "husky",
1414
"lint": "eslint .",
1515
"format": "prettier --write .",
16-
"commit": "commit"
16+
"commit": "commit",
17+
"build": "rollup -c"
1718
},
1819
"keywords": [
1920
"workshop",
@@ -28,11 +29,13 @@
2829
"@commitlint/config-conventional": "^19.6.0",
2930
"@commitlint/prompt-cli": "^19.7.0",
3031
"@eslint/js": "^9.18.0",
32+
"@rollup/plugin-terser": "^0.4.4",
3133
"eslint": "^9.18.0",
3234
"globals": "^15.14.0",
3335
"husky": "^9.1.7",
3436
"lint-staged": "^15.3.0",
3537
"prettier": "^3.4.2",
38+
"rollup": "^4.30.1",
3639
"vitest": "^2.1.8"
3740
},
3841
"lint-staged": {
@@ -41,4 +44,4 @@
4144
"prettier --write"
4245
]
4346
}
44-
}
47+
}

rollup.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import terser from "@rollup/plugin-terser";
2+
3+
export default {
4+
input: "src/mathy.js",
5+
output: {
6+
name: "mathy",
7+
file: "dist/bundle.js",
8+
format: "umd",
9+
plugins: [terser()]
10+
}
11+
};

src/mathy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { add } from "./add.js";

0 commit comments

Comments
 (0)