UNPKG

vite-esbuild-typescript-checker

Version:

* Speeds up [TypeScript](https://github.com/Microsoft/TypeScript) type checking * Supports [Vue Single File Component](https://vuejs.org/v2/guide/single-file-components.html) * Displays nice error messages with the [code frame](https://babeljs.io/docs/en/

84 lines (83 loc) 2.82 kB
import { Helper } from './helper.js'; import pc from 'picocolors'; import moment from 'moment'; import chokidar from 'chokidar'; import path, { dirname } from 'path'; import { fileURLToPath } from 'url'; import { forwardSlash } from './functions.js'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); export function RollupPlugin(config) { const defaultConfig = { watch: false, vue: { enabled: false } }; const pluginConfig = Object.assign({}, defaultConfig, config); const helper = new Helper(pluginConfig); return { name: 'vite-esbuild-typescript-checker', async buildStart (options) { const watcher = chokidar.watch([ path.resolve(_dirname, pluginConfig.basedir, '**/*.ts'), path.resolve(_dirname, pluginConfig.basedir, '**/*.vue') ], { ignored: [ /(^|[\/\\])\../, /node_modules/ ], persistent: true, ignoreInitial: true }); console.log(pc.yellow(`[${moment().format('Y-MM-DD H:mm:ss')}] Started checker`)); await helper.workerStart(); watcher.on('add', helper.addFile); watcher.on('change', helper.addFile); watcher.on('unlink', helper.deleteFile); }, async writeBundle (options) { await helper.workerStart(); } }; } export function VitePlugin(config) { const defaultConfig = { watch: false, vue: { enabled: false } }; const pluginConfig = Object.assign({}, defaultConfig, config); pluginConfig.basedir = forwardSlash(pluginConfig.basedir); const helper = new Helper(pluginConfig); return { name: 'vite-esbuild-typescript-checker', async configureServer ({ watcher, ws, config: { logger } }) { console.log(pc.yellow(`[${moment().format('Y-MM-DD H:mm:ss')}] Started checker`)); await helper.workerStart(ws); watcher.on('add', helper.addFile); watcher.on('change', helper.addFile); watcher.on('unlink', helper.deleteFile); }, async writeBundle (options) { await helper.workerStart(); } }; } export const EsbuildPlugin = (config)=>{ return { name: 'vite-esbuild-typescript-checker', setup (build) { const defaultConfig = { watch: false, vue: { enabled: false } }; const pluginConfig = Object.assign({}, defaultConfig, config); const helper = new Helper(pluginConfig); helper.workerStart(); } }; };