Skip to content

Commit

Permalink
feat: use esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 9, 2020
1 parent 2999775 commit 4cd6a1e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1,335 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tsup

A bundler focusing on TypeScript experience, based on Rollup.
Rollup + ESBundle.

## Install

Expand All @@ -14,6 +14,18 @@ yarn add tsup --dev

You can also install it globally but it's not recommended.

## Usage

```bash
tsup [...files]
```

For more details:

```bash
tsup --help
```

## License

MIT.
MIT © [EGOIST (Kevin Titor)](https://github.com/sponsors/egoist)
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
{
"name": "tsup",
"version": "1.0.0",
"main": "index.js",
"version": "0.0.0-semantic-release",
"main": "dist/index.js",
"bin": "dist/cli.js",
"files": [
"dist"
],
"author": "EGOIST",
"license": "MIT",
"devDependencies": {
"@types/node": "^13.9.2",
"cac": "^6.5.7",
"rollup": "^2.1.0",
"rollup-plugin-typescript2": "^0.26.0",
"ts-node": "^8.7.0"
"scripts": {
"build": "esbuild src/cli.ts --platform=node --outdir=dist --format=cjs --target=es2018 --external:rollup --external:rollup-plugin-esbuild --bundle",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@babel/core": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-typescript": "^7.8.3",
"rollup-plugin-babel": "^4.4.0",
"rollup": "^2.8.2",
"rollup-plugin-esbuild": "^1.2.0"
},
"devDependencies": {
"@types/node": "^13.9.2",
"cac": "^6.5.8",
"rollup-plugin-hashbang": "^2.2.2",
"typescript": "^3.8.3"
}
Expand Down
46 changes: 22 additions & 24 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#!/usr/bin/env node
import { readFileSync } from 'fs'
import {join} from 'path'
import { join } from 'path'
import { cac } from 'cac'

const cli = cac('tsup')

cli.command('[file]', 'Bundle a speific file')
.option('--format <format>', 'Bundle format')
.action(async (file: string, options) => {
const {rollup} = await import('rollup')
cli
.command('<...files>', 'Entry files')
.option('--format <format>', 'Bundle format')
.option('--minify', 'Minify bundle')
.option('--target <target>', 'Bundle target, "es20XX" or "esnext"', {
default: 'es2017',
})
.action(async (files: string[], options) => {
const { rollup } = await import('rollup')
const { default: hashbangPlugin } = await import('rollup-plugin-hashbang')
const { default: esbuildPlugin } = await import('rollup-plugin-esbuild')

return rollup({
input: file,
const result = await rollup({
input: files,
plugins: [
require('rollup-plugin-hashbang')(),
require('rollup-plugin-babel')({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
presets: [
[require.resolve('@babel/preset-env'), {
modules: false
}],
require.resolve('@babel/preset-typescript')
]
})
]
}).then(result => {
result.write({
dir: 'dist',
format: options.format || 'cjs'
})
hashbangPlugin(),
esbuildPlugin({ minify: options.minify, target: options.target }),
],
})
await result.write({
dir: 'dist',
format: options.format || 'cjs',
})
})

Expand All @@ -37,4 +35,4 @@ cli.help()
const pkgPath = join(__dirname, '../package.json')
cli.version(JSON.parse(readFileSync(pkgPath, 'utf8')).version)

cli.parse()
cli.parse()
Empty file removed src/index.ts
Empty file.

0 comments on commit 4cd6a1e

Please sign in to comment.