Skip to content

Commit

Permalink
feat: experimental plugin system (#486)
Browse files Browse the repository at this point in the history
Co-authored-by: EGOIST <0x142857@gmail.com>
Co-authored-by: 木杉 <zhmushan@qq.com>
  • Loading branch information
egoist and zhmushan committed Dec 10, 2021
1 parent 798f446 commit 524470c
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 536 deletions.
20 changes: 13 additions & 7 deletions docs/README.md
Expand Up @@ -72,7 +72,7 @@ All other CLI flags still apply to this command.

You can also use `tsup` using file configurations or in a property inside your `package.json`, and you can even use `TypeScript` and have type-safety while you are using it.

> Most of these options can be overwritten using the CLI options
> INFO: Most of these options can be overwritten using the CLI options
You can use any of these files:

Expand All @@ -82,7 +82,7 @@ You can use any of these files:
- `tsup.config.json`
- `tsup` property in your `package.json`

> In all the custom files you can export the options either as `tsup`, `default` or `module.exports =`
> INFO: In all the custom files you can export the options either as `tsup`, `default` or `module.exports =`
[Check out all available options](https://github.com/egoist/tsup/blob/master/src/options.ts).

Expand Down Expand Up @@ -218,7 +218,7 @@ To disable code splitting altogether, try the `--no-splitting` flag instead.

### ES5 support

You can use `--target es5` to compile the code down to es5, it's processed by [buble](http://buble.surge.sh/). Some features are NOT supported by this target, namely: `for .. of`.
You can use `--target es5` to compile the code down to es5, in this target your code will be transpiled by esbuild to es2020 first, and then transpiled to es5 by [SWC](https://swc.rc).

### Compile-time environment variables

Expand All @@ -240,24 +240,24 @@ tsup src/index.ts --watch

Turn on watch mode. This means that after the initial build, tsup will continue to watch for changes in any of the resolved files.

> By default it always ignores `dist`, `node_modules` & `.git`
> INFO: By default it always ignores `dist`, `node_modules` & `.git`
```bash
tsup src/index.ts --watch --ignore-watch ignore-this-folder-too
```

> You can specify more than a folder repeating "--ignore-watch", for example: `tsup src src/index.ts --watch --ignore-watch folder1 --ignore-watch folder2`
> INFO: You can specify more than a folder repeating "--ignore-watch", for example: `tsup src src/index.ts --watch --ignore-watch folder1 --ignore-watch folder2`
### onSuccess

You can specify command to be executed after a successful build, specially useful for **Watch mode**

> You should not use shell scripts, if you need to specify shell scripts you can add it in your "scripts" field and set for example `tsup src/index.ts --watch --onSuccess \"npm run dev\"`
```bash
tsup src/index.ts --watch --onSuccess "node dist/index.js"
```

> Warning: You should not use shell scripts, if you need to specify shell scripts you can add it in your "scripts" field and set for example `tsup src/index.ts --watch --onSuccess \"npm run dev\"`
### Minify output

You can also minify the output, resulting into lower bundle sizes by using the `--minify` flag.
Expand Down Expand Up @@ -364,6 +364,12 @@ For more details:
tsup --help
```

## Troubleshooting

### error: No matching export in "xxx.ts" for import "xxx"

This usualy happens when you have `emitDecoratorMetadata` enabled in your tsconfig.json, in this mode we use [SWC](https://swc.rc) to transpile decorators to JavaScript so exported types will be eliminated, that's why esbuild won't be able to find corresponding exports. You can fix this by changing your import statement from `import { SomeType }` to `import { type SomeType }` or `import type { SomeType }`.

## License

MIT &copy; [EGOIST](https://github.com/sponsors/egoist)
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -12,7 +12,7 @@
<!-- Stylesheet -->
<link
rel="stylesheet"
href="https://unpkg.com/@egoist/docup@1/dist/docup.min.css"
href="https://unpkg.com/@egoist/docup@2/dist/docup.min.css"
/>
</head>
<body>
Expand Down
11 changes: 4 additions & 7 deletions package.json
Expand Up @@ -29,7 +29,7 @@
"ts"
],
"require": [
"sucrase//register"
"sucrase/register"
]
},
"dependencies": {
Expand All @@ -44,22 +44,19 @@
"postcss-load-config": "^3.0.1",
"resolve-from": "^5.0.0",
"rollup": "^2.60.0",
"sucrase": "^3.20.1",
"tree-kill": "^1.2.2"
"tree-kill": "^1.2.2",
"source-map": "^0.7.3",
"sucrase": "^3.20.3"
},
"devDependencies": {
"@babel/core": "^7.13.15",
"@rollup/plugin-json": "^4.1.0",
"@swc/core": "^1.2.112",
"@types/babel__core": "^7.1.16",
"@types/buble": "^0.19.2",
"@types/debug": "^4.1.5",
"@types/flat": "^5.0.2",
"@types/fs-extra": "^9.0.11",
"@types/node": "^14.14.41",
"@types/resolve": "^1.20.0",
"ava": "^4.0.0-rc.1",
"buble": "^0.20.0",
"colorette": "^2.0.16",
"consola": "^2.15.3",
"flat": "^5.0.2",
Expand Down

0 comments on commit 524470c

Please sign in to comment.