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

feat(sync): Adds sync build step #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
"prerelease": "yarn verify",
"prebuild": "rimraf dist && mkdir dist && node prebuild.js && cp src/itty-router.d.ts dist",
"build": "yarn uglify",
"uglify": "yarn uglify:cjs && yarn uglify:esm",
"uglify": "yarn uglify:cjs && yarn uglify:cjs:sync && yarn uglify:esm && yarn uglify:esm:sync",
"uglify:esm": "uglifyjs dist/itty-router.mjs -c -m --toplevel > dist/itty-router.min.mjs",
"uglify:esm:sync": "uglifyjs dist/itty-router-sync.mjs -c -m --toplevel > dist/itty-router-sync.min.mjs",
"uglify:cjs": "uglifyjs src/itty-router.js -c -m --toplevel > dist/itty-router.min.js",
"uglify:cjs:sync": "uglifyjs dist/itty-router-sync.js -c -m --toplevel > dist/itty-router-sync.min.js",
"build:esm": "esbuild src/itty-router.js --format=esm --outfile=./dist/itty-router.mjs",
"postbuild": "node check-size.js",
"release": "release --tag --push"
Expand Down
10 changes: 10 additions & 0 deletions prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ const { readFileSync, writeFileSync } = require('fs-extra')

console.log('writing esm version.')
const base = readFileSync('./src/itty-router.js', { encoding: 'utf-8' })
writeFileSync('./dist/itty-router.mjs', base)
const baseSync = base
.replace('async handle', 'handle')
.replace('await handler', 'handler')
writeFileSync('./dist/itty-router-sync.js', baseSync)
const esm = base
.replace('function Router', 'export function Router')
.replace('module.exports =', 'export default')
.replace(/\s*\/\/[^\n]+/g, '')
writeFileSync('./dist/itty-router.mjs', esm)
const esmSync = baseSync
.replace('function Router', 'export function Router')
.replace('module.exports =', 'export default')
.replace(/\s*\/\/[^\n]+/g, '')
writeFileSync('./dist/itty-router-sync.mjs', esmSync)

const test = readFileSync('./src/itty-router.spec.js', { encoding: 'utf-8' })
const minifiedTest = test.replace('itty-router', 'itty-router.min.js')
Expand Down