Skip to content

Commit

Permalink
Convert core to use esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Jan 3, 2023
1 parent ea9c5a1 commit f711b46
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
60 changes: 60 additions & 0 deletions packages/core/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env node
const esbuild = require('esbuild')
const { nodeExternalsPlugin } = require('esbuild-node-externals')

let config = {
bundle: true,
minify: true,
sourcemap: true,
target: 'es2020',
plugins: [nodeExternalsPlugin()],
}

if (process.argv.slice(1).includes('--watch')) {
config.watch = {
onRebuild(error) {
if (error) console.error('watch build failed:', error)
else console.log('watch build succeeded')
},
}
}

esbuild
.build({
...config,
entryPoints: ['src/index.ts'],
format: 'esm',
outfile: 'dist/index.esm.js',
platform: 'browser',
})
.catch(() => process.exit(1))

esbuild
.build({
...config,
entryPoints: ['src/index.ts'],
format: 'cjs',
outfile: 'dist/index.js',
platform: 'browser',
})
.catch(() => process.exit(1))

esbuild
.build({
...config,
entryPoints: ['src/server.ts'],
format: 'esm',
outfile: 'dist/server.esm.js',
platform: 'node',
})
.catch(() => process.exit(1))

esbuild
.build({
...config,
entryPoints: ['src/server.ts'],
format: 'cjs',
outfile: 'dist/server.js',
platform: 'node',
})
.catch(() => process.exit(1))
24 changes: 15 additions & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@
],
"source": "src/index.ts",
"main": "dist/index.js",
"unpkg": "dist/index.umd.js",
"types": "types/index.d.ts",
"exports": {
".": "./dist/index.js",
"./server": "./dist/server.js"
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.js",
"types": "./types/index.d.js"
},
"./server": {
"import": "./dist/server.esm.js",
"require": "./dist/server.js",
"types": "./types/server.d.js"
}
},
"scripts": {
"build": "npm run clean && npm run build:browser && npm run build:server",
"build:browser": "microbundle --format es,cjs",
"build:server": "microbundle --format es,cjs --target node --output ./dist/server.js ./src/server.ts",
"build": "npm run clean && ./build.js && tsc --emitDeclarationOnly",
"clean": "rm -rf types && rm -rf dist",
"prepublishOnly": "npm run build",
"watch": "microbundle watch --format es,cjs"
"watch": "./build.js --watch"
},
"dependencies": {
"axios": "^0.27.0",
Expand All @@ -48,7 +53,8 @@
"@types/node": "^14.0",
"@types/nprogress": "^0.2.0",
"@types/qs": "^6.9.0",
"microbundle": "^0.12.0",
"typescript": "^4.2.4"
"esbuild": "^0.16.13",
"esbuild-node-externals": "^1.6.0",
"typescript": "^4.9.4"
}
}
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export { default as setupProgress } from './progress'
export { default as shouldIntercept } from './shouldIntercept'
export * from './types'
export { hrefToUrl, mergeDataIntoQueryString, urlWithoutHash } from './url'
export { type Router }

export const router = new Router()

0 comments on commit f711b46

Please sign in to comment.