Skip to content

Commit

Permalink
chore: dev with typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww committed Aug 6, 2023
1 parent 796253a commit 99283ca
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/app-renderer/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"extends": "@ter/eslint-config/.eslintrc.react.js",
"ignorePatterns": ["/coverage", "*.cjs", "*.js", "*.mjs"],
"parserOptions": {
"project": ["./tsconfig.json", "./tsconfig.node.json"]
"project": ["./tsconfig.json", "./tsconfig.vite.json"]
}
}
1 change: 1 addition & 0 deletions packages/app-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"typescript": "5.1.3",
"typescript-plugin-css-modules": "^5.0.1",
"vite": "^4.4.0",
"vite-plugin-checker": "^0.6.1",
"vite-tsconfig-paths": "^4.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/app-renderer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
},
"include": ["src/**/*"],
"exclude": [],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [{ "path": "./tsconfig.vite.json" }]
}
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/app-renderer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { getElectronChromeTarget } from '@ter/scripts';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { checker } from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), tsconfigPaths()],
export default defineConfig(({ command }) => ({
plugins: [react(), tsconfigPaths(), command === 'serve' && checker({ typescript: true })],
build: {
outDir: '../../build',
target: getElectronChromeTarget(),
Expand All @@ -16,4 +17,4 @@ export default defineConfig({
server: {
port: 4321,
},
});
}));
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"babel-preset-react-app": "^10.0.1",
"camelcase": "^6.3.0",
"chalk": "^4.1.2",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
Expand Down
31 changes: 29 additions & 2 deletions packages/scripts/src/webpack/webpack.main.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import path from 'node:path';
import TerserPlugin from 'terser-webpack-plugin';
import type { Configuration } from 'webpack';
import type { Configuration, WebpackPluginInstance } from 'webpack';

import { paths } from '../utils';

Expand Down Expand Up @@ -197,7 +198,33 @@ const factory: ConfigurationFactory = (env, argv) => {
],
},

plugins: isEnvDevelopment ? [new ReloadElectronWebpackPlugin(paths.repository, paths.working)] : [],
plugins: [
isEnvDevelopment && new ReloadElectronWebpackPlugin(paths.repository, paths.working),
// TypeScript type checking
isEnvDevelopment &&
new ForkTsCheckerWebpackPlugin({
async: isEnvDevelopment,
typescript: {
typescriptPath: require.resolve('typescript'),
configOverwrite: {
compilerOptions: {
sourceMap: isEnvProduction || isEnvDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
noEmit: true,
incremental: true,
tsBuildInfoFile: appMainPaths.appTsBuildInfoFile,
},
},
context: appMainPaths.appPath,
diagnosticOptions: {
syntactic: true,
},
mode: 'write-references',
},
}),
].filter(Boolean) as WebpackPluginInstance[],

watch: isEnvDevelopment,
watchOptions: {
Expand Down
Loading

0 comments on commit 99283ca

Please sign in to comment.