feat(cli): enable type checking

This commit is contained in:
chenjiahan
2020-05-27 21:13:21 +08:00
parent 26a7cc5d3c
commit f508d2e6c0
4 changed files with 63 additions and 8 deletions

View File

@@ -1,7 +1,11 @@
import sass from 'sass';
import FriendlyErrorsPlugin from '@nuxt/friendly-errors-webpack-plugin';
import { VueLoaderPlugin } from 'vue-loader';
import { join } from 'path';
import { existsSync } from 'fs';
import { consola } from '../common/logger';
import {
CWD,
CACHE_DIR,
STYLE_EXTS,
SCRIPT_EXTS,
@@ -28,6 +32,36 @@ const CSS_LOADERS = [
},
];
const plugins = [
new VueLoaderPlugin(),
new FriendlyErrorsPlugin({
clearConsole: false,
logLevel: 'WARNING',
}),
];
const tsconfigPath = join(CWD, 'tsconfig.json');
console.log('tsconfigPath', existsSync(tsconfigPath));
if (existsSync(tsconfigPath)) {
const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
plugins.push(
new ForkTsCheckerPlugin({
formatter: 'codeframe',
vue: { enabled: true },
logger: {
// skip info message
info() {},
warn(message: string) {
consola.warn(message);
},
error(message: string) {
consola.error(message);
},
},
})
);
}
export const baseConfig = {
mode: 'development',
resolve: {
@@ -83,11 +117,5 @@ export const baseConfig = {
},
],
},
plugins: [
new VueLoaderPlugin(),
new FriendlyErrorsPlugin({
clearConsole: false,
logLevel: 'WARNING',
}),
],
plugins,
};