Vue CLI plugin that adds comprehensive TypeScript support to Vue.js projects with webpack configuration, project scaffolding, and build optimization.
—
Main plugin function that configures webpack for TypeScript compilation with performance optimizations including caching, parallel processing, and type checking.
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:
.ts and .tsx file extension resolutionUsage 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
}
};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$/);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):
cache-loader for build cachingparallel option is enabled@vue/cli-plugin-babel is presentBuild 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'
};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
};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
};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
}
}
};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-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:
thread-loadercache-loaderfork-ts-checker-webpack-pluginInstall with Tessl CLI
npx tessl i tessl/npm-vue--cli-plugin-typescript