Broccoli TypeScript Compiler

8.0.0 · active · verified Sun Apr 19

Broccoli TypeScript Compiler (broccoli-typescript-compiler) is a specialized Broccoli plugin designed to integrate TypeScript compilation directly into a Broccoli.js build pipeline. Currently stable at version 8.0.0, this package provides robust tooling for converting TypeScript files into JavaScript, supporting both CommonJS and ES modules targets. It allows for flexible configuration via `tsconfig.json` files or inline objects, enabling developers to define compiler options such as module resolution, target ES version, source maps, and declaration file generation. Key differentiators include its tight integration with the Broccoli ecosystem, offering three distinct usage patterns: a direct compilation function, a class-based compiler for more control, and a filter function that intelligently processes only TypeScript files while passing non-TypeScript assets through. While a specific release cadence isn't published, the project actively maintains compatibility with recent TypeScript versions, ensuring it remains a viable solution for Broccoli-based projects requiring TypeScript support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates compiling TypeScript files within a Broccoli build, using a custom tsconfig and handling production error settings.

import typescript from 'broccoli-typescript-compiler';
import funnel from 'broccoli-funnel';
import mergeTrees from 'broccoli-merge-trees';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const inputTree = funnel('.', { exclude: ['node_modules/**', 'dist/**'] });

const compiledJS = typescript(inputTree, {
  tsconfig: {
    compilerOptions: {
      module: 'commonjs',
      target: 'es2018',
      moduleResolution: 'node',
      newLine: 'LF',
      rootDir: '.', // Assuming root directory
      outDir: 'dist',
      sourceMap: true,
      declaration: true,
    },
    files: ['index.ts', 'src/**/*.ts'], // Adjust files as needed for your project
  },
  throwOnError: process.env.NODE_ENV === 'production',
  annotation: 'Compile application TypeScript',
});

// Example of merging compiled JS with other assets if needed
export default mergeTrees([compiledJS /*, otherTrees */], { overwrite: true });

view raw JSON →