rollup-plugin-esbuild
TypeScript icon, indicating that this package has built-in type declarations

6.2.1 • Public • Published

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


rollup-plugin-esbuild

npm version npm downloads

esbuild is by far one of the fastest TS/ESNext to ES6 compilers and minifier, this plugin replaces rollup-plugin-typescript2, @rollup/plugin-typescript and rollup-plugin-terser for you.

Install

yarn add esbuild rollup-plugin-esbuild --dev

Usage

In rollup.config.js:

import esbuild from 'rollup-plugin-esbuild'

export default {
  plugins: [
    esbuild({
      // All options are optional
      include: /\.[jt]sx?$/, // default, inferred from `loaders` option
      exclude: /node_modules/, // default
      sourceMap: true, // default
      minify: process.env.NODE_ENV === 'production',
      target: 'es2017', // default, or 'es20XX', 'esnext'
      jsx: 'transform', // default, or 'preserve'
      jsxFactory: 'React.createElement',
      jsxFragment: 'React.Fragment',
      // Like @rollup/plugin-replace
      define: {
        __VERSION__: '"x.y.z"',
      },
      tsconfig: 'tsconfig.json', // default
      // Add extra loaders
      loaders: {
        // Add .json files support
        // require @rollup/plugin-commonjs
        '.json': 'json',
        // Enable JSX in .js files too
        '.js': 'jsx',
      },
    }),
  ],
}
  • include and exclude can be String | RegExp | Array[...String|RegExp], when supplied it will override default values.
  • It uses jsx, jsxDev, jsxFactory, jsxFragmentFactory and target options from your tsconfig.json as default values.

Declaration File

There are serveral ways to generate declaration file:

  • Use tsc with emitDeclarationOnly, 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, also does type checking.
  • Use api-extractor by Microsoft, looks quite complex to me so I didn't try it, PR welcome to update this section.

Use with Vue JSX

Use this with rollup-plugin-vue-jsx:

import vueJsx from 'rollup-plugin-vue-jsx-compat'
import esbuild from 'rollup-plugin-esbuild'

export default {
  // ...
  plugins: [
    vueJsx(),
    esbuild({
      jsxFactory: 'vueJsxCompat',
    }),
  ],
}

Standalone Minify Plugin

If you only want to use this plugin to minify your bundle:

import { minify } from 'rollup-plugin-esbuild'

export default {
  plugins: [minify()],
}

Optimizing Deps

You can use this plugin to pre-bundle dependencies using esbuild and inline them in the Rollup-generated bundle:

esbuild({
  optimizeDeps: {
    include: ['vue', 'vue-router'],
  },
})

This eliminates the need of @rollup/plugin-node-modules and @rollup/plugin-commonjs.

Note that this is an experimental features, breaking changes might happen across minor version bump.

TODO: Maybe we can scan Rollup input files to get a list of deps to optimize automatically.

Sponsors

sponsors

License

MIT © EGOIST (Kevin Titor)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
6.2.194,321latest

Version History

VersionDownloads (Last 7 Days)Published
6.2.194,321
6.2.054,620
6.1.1110,594
6.1.013,603
6.0.2303
6.0.1127
6.0.03
5.0.043,838
4.10.314,997
4.10.2111
4.10.14,786
4.10.06
4.9.31,855
4.9.21
4.9.18,366
4.9.01
4.8.23,904
4.8.13
4.8.01
4.7.21,496
4.7.12
4.7.03
4.6.11
4.6.03,902
4.5.04,127
4.4.01
4.3.11
4.3.01
4.2.31,516
4.2.21
4.2.11
4.2.01
4.1.0227
4.0.118
4.0.01
3.0.4640
3.0.31
3.0.235
3.0.11
3.0.03
2.6.12,269
2.6.019
2.5.253
2.5.11
2.5.06
2.4.25
2.4.11
2.4.01
2.3.014
2.2.088
2.1.02
1.5.13
2.0.06
1.4.11
1.4.01
1.3.31
1.3.21
1.3.11
1.3.01
1.2.11
1.2.01
1.1.01
1.0.11
1.0.01

Package Sidebar

Install

npm i rollup-plugin-esbuild

Weekly Downloads

365,899

Version

6.2.1

License

MIT

Unpacked Size

26.8 kB

Total Files

7

Last publish

Collaborators

  • egoist
OSZAR »