6.2.1 • Published 2 months ago

rollup-plugin-esbuild v6.2.1

Weekly downloads
12,385
License
MIT
Repository
github
Last release
2 months ago

💛 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)

@real-bird/cdd-wanted@visibly/vui@uponco/adminvue-cli-plugin-dmap@skulpture/serve@infinitebrahmanuniverse/nolb-rollup-plugin-e@everything-registry/sub-chunk-2680lt-web-framemedusa-admin-fa@xonon/cli@perseides/admintcoffe-buildertcoffe-clitailscale-apitailscale-api-tssveltekit-adapter-versioned-workersveltekit-plugin-versioned-workerwind-ui-1wheel-vue3xk5-editor-vue3spermthiggle-api-clientvite-babylonjsvite-plugin-md-plusvite-plugin-mock-linkvscode-scriptsvthree-form-designvite-plugin-cloudflare-workervite-plugin-esbuild-postvd2hcvendor-alpha-v1@directus/extensions-sdk@directus9/extensions-sdk@dotaddon/packer@dpayoams/extensions-sdk@dimensio/extensions-sdk@dofu/infra@drewfle/bundler@rosinfo.tech/cli@princemwase/medusa-admin@payglo/admin@runafe/tools-buildivue-ui-1json-categorizekeystar-uikyberutils@alisafavi123/adminsame-thingss-ioc-ui@adaliszk/rollup-esbuildndst@purnasatria/directus-extension-document-interfacega-custom-react-sortable-treeioc-componentssuhan-capture-sdktest-admin-ats-project-builder@arc-directus/extensions-sdk@arayutw/emitter@arayutw/matrix-pointer@aiabdelbaqy/vue-country-tel-input@alauda/dp-cli@ajeebsa/admin@alqmc/build-ts@alqmc/build-vue@aliyun-obv/obviz-cli@allyaw/cli@baicie/build@backstage/cli@baleada/prepare@beesbuild/cli@beesbuild/utils@barbuza/vite-plugin-service-worker@agiflowai/rig-rollup-config@blgc/cli@bit-vtex-test/lib-to-install-bit-test-vtex@brixtol/rollup-config@carv/snowpack-plugin-rollup@ccom-eds-composer/composer@clairview/extensions-sdk@charrue/vue2-bundler@charrue/vue3-bundler@db-studio/extensions-sdk@dfatwork-pkgs/backstage-cli@dfatwork-pkgs/janus-cli@digicube/extensions-sdk@digital-realty/ix-notificationsz-ui-1yui-test-v2yzbuildvue-uniframe-data-visualvue2-componentsvue3-pure-wheelwebloaf-tempv3-usehookuscript-build@fattypanda/rbuilder@habbaldev78y/admin@growing-web/esm-pack-core@growing-web/esmpack-builder
6.2.1

2 months ago

6.2.0

3 months ago

6.1.1

1 year ago

6.1.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.2

2 years ago

4.10.2

2 years ago

4.10.3

2 years ago

5.0.0

2 years ago

4.10.1

3 years ago

4.10.0

3 years ago

4.9.3

3 years ago

4.9.2

3 years ago

4.9.0

3 years ago

4.9.1

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.8.2

3 years ago

4.7.2

3 years ago

4.7.1

3 years ago

4.7.0

3 years ago

4.6.1

3 years ago

4.6.0

4 years ago

4.5.0

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.3

4 years ago

4.2.2

4 years ago

4.1.0

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.1

5 years ago

2.4.2

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

1.5.1

5 years ago

2.1.0

5 years ago

1.5.0

5 years ago

2.0.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.3

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago