rollup-plugin-esbuild

**💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).**

MIT 65 个版本
安装
npm install rollup-plugin-esbuild
yarn add rollup-plugin-esbuild
pnpm add rollup-plugin-esbuild
bun add rollup-plugin-esbuild
README

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

版本列表
6.2.1 2025-02-27
6.2.0 2025-02-05
6.1.1 2024-01-23
6.1.0 2023-10-08
6.0.2 2023-09-28
6.0.1 2023-09-21
6.0.0 2023-09-20
5.0.0 2022-11-08
4.10.3 2022-11-08
4.10.2 2022-11-07
4.10.1 2022-08-26
4.10.0 2022-08-26
4.9.3 2022-08-15
4.9.2 2022-08-14
4.9.1 2022-04-06
4.9.0 2022-04-06
4.8.2 2021-12-29
4.8.1 2021-12-26
4.8.0 2021-12-26
4.7.2 2021-11-19
4.7.1 2021-11-18
4.7.0 2021-11-18
4.6.1 2021-11-18
4.6.0 2021-10-15
4.5.0 2021-06-03
4.4.0 2021-06-03
4.3.1 2021-06-02
4.3.0 2021-06-02
4.2.3 2021-04-28
4.2.2 2021-04-28
4.2.1 2021-04-28
4.2.0 2021-04-28
4.1.0 2021-04-21
4.0.1 2021-04-16
4.0.0 2021-04-16
3.0.4 2021-04-16
3.0.3 2021-04-16
3.0.2 2021-03-11
3.0.1 2021-03-11
3.0.0 2021-03-09
2.6.1 2020-12-11
2.6.0 2020-11-27
2.5.2 2020-10-10
2.5.1 2020-10-09
2.5.0 2020-09-01
2.4.2 2020-07-19
2.4.1 2020-07-18
2.4.0 2020-07-18
2.3.0 2020-07-16
2.2.0 2020-07-16
2.1.0 2020-06-15
2.0.0 2020-06-15
1.5.1 2020-06-15
1.5.0 2020-06-15
1.4.1 2020-05-13
1.4.0 2020-05-13
1.3.3 2020-05-12
1.3.2 2020-05-10
1.3.1 2020-05-09
1.3.0 2020-05-09
1.2.1 2020-05-09
1.2.0 2020-05-09
1.1.0 2020-05-09
1.0.1 2020-05-09
1.0.0 2020-05-09