feat: use esbuild

This commit is contained in:
EGOIST 2020-05-10 00:43:59 +08:00
parent 299977544a
commit 4cd6a1e2f7
5 changed files with 67 additions and 1335 deletions

View File

@ -1,6 +1,6 @@
# tsup
A bundler focusing on TypeScript experience, based on Rollup.
Rollup + ESBundle.
## Install
@ -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)

View File

@ -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"
}

View File

@ -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',
})
})
@ -37,4 +35,4 @@ cli.help()
const pkgPath = join(__dirname, '../package.json')
cli.version(JSON.parse(readFileSync(pkgPath, 'utf8')).version)
cli.parse()
cli.parse()

View File

1313
yarn.lock

File diff suppressed because it is too large Load Diff