CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vue--cli-plugin-typescript

Vue CLI plugin that adds comprehensive TypeScript support to Vue.js projects with webpack configuration, project scaffolding, and build optimization.

Pending
Overview
Eval results
Files

webpack-config.mddocs/

Webpack Configuration

Main plugin function that configures webpack for TypeScript compilation with performance optimizations including caching, parallel processing, and type checking.

Capabilities

Main Plugin Function

Configures webpack to handle TypeScript files with optimization features.

/**
 * Main plugin function that configures webpack for TypeScript compilation
 * Adds TypeScript loaders, optimizations, and type checking to webpack configuration
 * @param api - Vue CLI service API instance with chainWebpack access
 * @param projectOptions - Project configuration options including parallel settings
 */
function plugin(api, projectOptions): void;

Configuration Applied:

  • Adds .ts and .tsx file extension resolution
  • Sets up TypeScript compilation chain with multiple loaders
  • Configures fork-ts-checker-webpack-plugin for type checking
  • Enables performance optimizations based on environment and options

Usage Example:

// Applied automatically by Vue CLI when plugin is installed
// Manual usage (not typical):
const tsPlugin = require('@vue/cli-plugin-typescript');
// In vue.config.js
module.exports = {
  configureWebpack: config => {
    // Plugin is applied automatically via Vue CLI plugin system
  }
};

Webpack Chain Configuration

The plugin modifies webpack configuration through the Vue CLI's webpack-chain API:

/**
 * Webpack configuration modifications applied by the plugin
 * These are applied automatically when the plugin is loaded
 */

// Entry point modification (if no pages config)
config.entry('app').clear().add('./src/main.ts');

// Extension resolution
config.resolve.extensions.prepend('.ts').prepend('.tsx');

// Loader configuration
config.module.rule('ts').test(/\.ts$/);
config.module.rule('tsx').test(/\.tsx$/);

Loader Chain Setup

Configures the TypeScript loader chain with conditional optimizations:

/**
 * Loader configuration function used internally
 * @param loaderConfig - Configuration object for a specific loader
 * @param loaderConfig.name - Loader identifier
 * @param loaderConfig.loader - Loader module path
 * @param loaderConfig.options - Loader-specific options
 */
function addLoader({ name, loader, options }): void;

Loader Chain (in order):

  1. cache-loader (optional): cache-loader for build caching
  2. thread-loader (conditional): Multi-threaded processing when parallel option is enabled
  3. babel-loader (conditional): Babel integration when @vue/cli-plugin-babel is present
  4. ts-loader: TypeScript compilation with transpile-only mode

Cache Configuration

Build caching configuration for improved performance:

/**
 * Cache configuration automatically applied when cache-loader is available
 * Caches TypeScript compilation results in node_modules/.cache/ts-loader
 */
const cacheConfig = {
  'ts-loader': 'ts-loader package version',
  'typescript': 'typescript package version', 
  modern: 'modern build flag'
};

Thread Configuration

Parallel processing configuration for multi-core systems:

/**
 * Thread loader configuration applied when parallel option is enabled
 * @param projectOptions.parallel - Boolean or number for thread count
 */
const threadConfig = {
  workers: typeof projectOptions.parallel === 'number' 
    ? projectOptions.parallel 
    : undefined
};

TypeScript Loader Options

Core TypeScript compilation settings:

/**
 * TypeScript loader configuration applied to both .ts and .tsx files
 */
const tsLoaderOptions = {
  transpileOnly: true,           // Skip type checking for performance
  appendTsSuffixTo: ['\\.vue$'], // Handle Vue SFC TypeScript blocks
  happyPackMode: boolean         // Enable when using thread-loader
};

const tsxLoaderOptions = {
  // Same as tsLoaderOptions but with:
  appendTsxSuffixTo: ['\\.vue$'] // Handle Vue SFC TSX blocks
};

Fork TypeScript Checker Configuration

Off-thread type checking configuration:

/**
 * Fork TypeScript checker plugin configuration
 * Provides type checking without blocking webpack compilation
 */
const forkTsCheckerConfig = {
  typescript: {
    extensions: {
      vue: {
        enabled: true,
        compiler: string // Path to Vue compiler (vue/compiler-sfc or vue-template-compiler)
      }
    },
    diagnosticOptions: {
      semantic: true,
      syntactic: boolean // Based on useThreads setting
    }
  }
};

Vue Compiler Integration

Automatic Vue compiler detection and configuration:

/**
 * Vue compiler path resolution for different Vue versions
 * Automatically detects and configures appropriate compiler
 */
let vueCompilerPath: string;

// Vue 2.7+ detection
try {
  vueCompilerPath = require.resolve('vue/compiler-sfc');
} catch (e) {
  // Vue 2.6 and lower fallback
  vueCompilerPath = require.resolve('vue-template-compiler');
}

Environment Configuration

Environment-specific configuration handling:

/**
 * Environment and project-specific configuration
 */
const environmentConfig = {
  useThreads: boolean,           // process.env.NODE_ENV === 'production' && !!projectOptions.parallel
  modernBuild: boolean,          // process.env.VUE_CLI_MODERN_BUILD
  isTestEnvironment: boolean     // process.env.VUE_CLI_TEST
};

Performance Features:

  • Parallel processing on multi-core systems via thread-loader
  • Build caching via cache-loader
  • Off-thread type checking via fork-ts-checker-webpack-plugin
  • Transpile-only mode for faster compilation
  • Modern build support for differential loading

Install with Tessl CLI

npx tessl i tessl/npm-vue--cli-plugin-typescript

docs

file-conversion.md

index.md

project-generation.md

project-migration.md

webpack-config.md

tile.json