- 6/21/21 - DEPRECATED REPO, NO LONGER USED.
esbuild is by far one of the fastest TS/ESNext to ES6 compilers, so it makes sense to use it over Babel/TSC with Rollup to take advantage of both worlds (Speed and the Rollup plugin ecosytem).
yarn add rollup-plugin-esbuild --dev
In rollup.config.js
:
import esbuild from 'rollup-plugin-esbuild'
export default {
plugins: [
esbuild({
// All options are optional
include: /\.[jt]sx?$/, // default
exclude: /node_modules/, // default
watch: process.argv.includes('--watch'),
minify: process.env.NODE_ENV === 'production',
target: 'es2017' // default, or 'es20XX', 'esnext'
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment'
// Like @rollup/plugin-replace
define: {
__VERSION__: '"x.y.z"'
}
}),
],
}
include
andexclude
can beString | RegExp | Array[...String|RegExp]
, when supplied it will override default values.
There are serveral ways to generate declaration file:
- Use
tsc
withemitDeclarationOnly
, the slowest way but you get type checking, it doesn't bundle the.d.ts
files. - Use
rollup-plugin-dts
which generates and bundle.d.ts
, no type checking so it's very fast. - Use
api-extractor
by Microsoft, looks quite complex to me so I didn't try it, PR welcome to update this section.
How do I get type checking then? VS Code only shows type errors for opened files!
You can enable type checking in testing, for example use jest with ts-jest to run tests, here's an example jest config file.
MIT © EGOIST (Kevin Titor)