@ts-tools/webpack-loader

5.0.2 • Public • Published

@ts-tools/webpack-loader

npm version

TypeScript loader for webpack.

Features:

  • Fast! Uses ts.transpileModule. Leaves type checking to other flows.
  • Uses persistent disk caching (node_modules/.cache/ts-<moodule>-<target>). Second run will not re-transpile a file if not changed.
  • Loads configuration from the closest tsconfig.json.
  • Automated source map configuration based on current devtool configuration.

Getting started

Install the library as a dev dependency in an existing TypeScript project:

npm i @ts-tools/webpack-loader --save-dev

And adjust your webpack configuration to include:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: '@ts-tools/webpack-loader',
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.mjs', '.js', '.json'],
  },
  // ...
};

Options

interface ITypeScriptLoaderOptions {
  /**
   * Keys to override in the `compilerOptions` section of the
   * `tsconfig.json` file.
   */
  compilerOptions?: object;

  /**
   * Turn persistent caching on/off.
   *
   *  @default true
   */
  cache?: boolean;

  /**
   * Absolute path of an existing directory to use for persistent cache.
   *
   * @default uses `find-cache-dir` to search for caching path.
   */
  cacheDirectoryPath?: string;

  /**
   * Path to `tsconfig.json` file.
   * Specifying it will skip config lookup
   */
  configFilePath?: string;

  /**
   * Name of config file to search for when looking up config.
   *
   * @default 'tsconfig.json'
   */
  configFileName?: string;

  /**
   * Should loader search for config.
   * Loader will search for the closest tsconfig file to the root context, and load it.
   *
   * @default true
   */
  configLookup?: boolean;
}

Options can be provided via the webpack configuration:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: '@ts-tools/webpack-loader',
        options: {
          compilerOptions: {
            target: 'es5',
          },
        },
      },
    ],
  },
  // ...
};

Similar projects

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 5.0.2
    637
    • latest

Version History

Package Sidebar

Install

npm i @ts-tools/webpack-loader

Weekly Downloads

767

Version

5.0.2

License

MIT

Unpacked Size

24.1 kB

Total Files

13

Last publish

Collaborators

  • avi.vahl