Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Usage with TypeScript? #6

Description

@mindplay-dk

Have you managed to use this plugin with TypeScript?

I'm hoping to use Babel only for my production build, and just work with ES6 via ESBuild during development.

I'm using a setup like the following:

esbuild.build({
  entryPoints: [
    "src/foo.ts",
    "src/bar.ts",
  ],
  outdir: "dist",
  bundle: true,
  minify: true,
  sourcemap: "external",
  target: "es5",
  plugins: [
    babel({
      config: {
        plugins: [
          "@babel/plugin-syntax-typescript" // doesn't work??
        ],
        presets: [
          ['@babel/preset-env', { targets: "ie 11, not ie_mob 11" }]
        ],
      }
    })
  ]
})
  .catch(() => process.exit(1));

Because Babel (in the plugin) runs before the TypeScript transform in ESBuild itself, any TS syntax ends up going to Babel - which crashes at the first type-hint.

I could enable @babel/preset-typescript, but then the TS transform would be performed by Babel rather than ESBuild - and they might work the same, but I'm not sure I should trust it? (I'm sure it's not as fast as ESBuild either.)

I tried adding @babel/plugin-syntax-typescript to config.plugins in the plugin configuration - this should give me support for TypeScript syntax without any transformations, as far as I understand. There's no real documentation for it. But this plugin doesn't appear to pick up this option? It doesn't complain either, so there's no telling if it has seen the option or not.

I'm not sure if syntax plugins work the same way as regular plugins?

Do we need to do something to suppor them in this plugin?

How else would you be able to use this plugin with TypeScript?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions