npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-esbuild-transform

v1.5.0

Published

Use esbuild with Rollup to transform any supported content types.

Downloads

578

Readme

rollup-plugin-esbuild-transform

Use esbuild with Rollup to transform any supported content types.

npm GitHub Workflow Status (branch) Codecov branch libera manifesto

Why

esbuild as a bundler has some problems such as #475 which has still not been fixed since Oct, 2020.

rollup-plugin-esbuild is great but there is no simpler way to use multiple loader with different options, and for some reason it does not provide all available options from esbuild transform API.

Install

npm install -D esbuild rollup-plugin-esbuild-transform

Example

// rollup.config.js

import { join } from 'path'
import esbuild from 'rollup-plugin-esbuild-transform'

export default {
  // ...
  plugins: [
    esbuild([
      {
        loader: 'json'
      },
      {
        loader: 'tsx',
        legalComments: 'eof'
      },
      {
        loader: 'ts',
        include: /\.tsx?$/,
        tsconfig: join(__dirname, 'tsconfig.json')
      },
      {
        output: true,
        minify: true,
        target: 'es2015'
      }
    ])
  ]
}

Options

// index.d.ts

import { TransformOptions as EsbuildTransformOptions } from 'esbuild'
import { FilterPattern } from '@rollup/pluginutils'
import { Plugin } from 'rollup'

export interface TransformOptions extends EsbuildTransformOptions {
  tsconfig?: string
}

export interface Options extends TransformOptions {
  output?: boolean
  include?: FilterPattern
  exclude?: FilterPattern
}

declare function esbuildTransform(options?: Options | Options[]): Plugin
export default esbuildTransform

This plugin uses the same options from esbuild transform API.

tsconfig is the path to tsconfig.json file relative to process.cwd(). It will not be used if tsconfigRaw is provided.

output is for indicating whether this transformation should be performed after the chunk (bundle) has been rendered.

include and exclude are picomatch patterns. They can be string | RegExp | Array<string | RegExp>. When supplied they will override the default values.

If output: true, then the options include and exclude will be applied to the chunk's filename from RollupOptions.output.file.

include

Default to new RegExp(`\\.(?:${loaderExtensions.join('|')})$`) (supports .cjs, .mjs, .cts, .mts), or undefined (match any filename) if output: true.

If a file is matched by more than one pattern (as the example below), the options other than loader will be shallowly merged into and possibly override the previous ones.

// options
[
  {
    loader: 'tsx',
    legalComments: 'eof'
  },
  {
    loader: 'ts',
    include: /\.tsx?$/,
    tsconfig: join(__dirname, 'tsconfig.json')
  }
]

// the final transform options for `index.tsx` will become
{
  loader: 'tsx',
  legalComments: 'eof',
  tsconfig: join(__dirname, 'tsconfig.json')
}

exclude

Default to /node_modules/, or undefined if output: true.

It takes priority over include.

Other default options

// output: false | undefined
{
  format: options.loader === 'json' ? 'esm' : undefined,
  sourcefile: id, // the resolved file path
  sourcemap: true,
  ...options
}

// output: true
{
  sourcefile: chunk.fileName,
  sourcemap: true,
  ...options
}

License

MIT License © 2021 Exuanbo