Razzle TypeScript Plugin

4.2.18 · maintenance · verified Sun Apr 19

razzle-plugin-typescript integrates TypeScript support into Razzle applications, allowing developers to use TypeScript for both client-side and server-side code. It provides granular configuration options for underlying tools like `ts-loader` and `fork-ts-checker-webpack-plugin`, enabling custom setups for compilation and type checking. The package is currently at version 4.2.18, receiving updates in sync with the core Razzle framework. A key consideration is that Razzle now includes built-in TypeScript support via Babel. As such, this plugin is primarily recommended for projects requiring advanced or specific TypeScript configurations, such as applying certain Babel transforms to `.ts` files, rather than for basic TypeScript integration, where the native Razzle support is generally sufficient and simpler.

Common errors

Warnings

Install

Imports

Quickstart

This configuration enables the TypeScript plugin in Razzle with custom `ts-loader` and `fork-ts-checker-webpack-plugin` options, and adds TypeScript extensions to Webpack's resolution paths.

/* razzle.config.js */
const RazzlePluginTypescript = require('razzle-plugin-typescript'); // Not strictly imported, but for context of plugin availability

module.exports = {
  plugins: [
    {
      name: 'typescript',
      options: {
        // Set useBabel to true if you want to keep using babel for JS/TS interoperability,
        // or if you want to apply any babel transforms to typescript files.
        useBabel: false,
        // Override ts-loader options
        tsLoader: {
          transpileOnly: true,
          experimentalWatchApi: true,
        },
        // Override fork-ts-checker-webpack-plugin options for type checking
        forkTsChecker: {
          eslint: {
            files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
          },
          async: process.env.NODE_ENV === 'development',
          formatter: 'codeframe',
        },
      },
    },
  ],
  // Optional: Add '.ts' and '.tsx' to Razzle's default extensions
  modifyWebpackConfig(config, { target, dev }, webpack) {
    config.resolve.extensions = [...config.resolve.extensions, '.ts', '.tsx'];
    return config;
  }
};

// Ensure required peer dependencies are installed: 
// yarn add -D typescript ts-loader fork-ts-checker-webpack-plugin
// Also, ensure a tsconfig.json exists in your project root.

view raw JSON →