Skip to content

Ensure webpack does not try to transpile server files. Fixes #1016

Antoine requested to merge ZeHiro/kresus:ts-client into master

This MR provides a tsconfig.json file for the client.
What are the problems ?

  1. The way ts-loader is currently configured, makes it impossible to transpile .ts code inside client/, because the loader implicitly uses the tsconfig.json at the root of the project, which excludes the client/ directory, and includes server/ (this is the cause of #1016 (closed)).
    How to fix : create a proper tsconfig.json file for the client.
  2. The full transpiling of the server/shared directories is done for each TS file in the shared directory (this would be the same if the client directory would be in the scope of the transpiler.
    How to fix : ts-loader has an option to transpile only the files to be added to the bundle: onlyCompileBundledFiles (see : https://github.com/TypeStrong/ts-loader#onlycompilebundledfiles). This could be useful.
  3. If we activate checkJs option, the transpiler also checks node_modules files: https://github.com/TypeStrong/ts-loader/issues/702 (proposed fix does not work) How to fix : 2 options (they can be combined).
  • disable checkJs option in ts-loader config (in webpack.config.js), to override client tsconfig.json
  • activate onlyCompileBundledFiles, so only the ts files are checked
    and for each option, introduce a new script to check javascript accross full client (without emitting any file), which would be used in parrallel (there is no problem to use checkJs with tsc directly).

My proposal

  1. Create a tsconfig.json for the client which could be use directly by tsc (with noEmit: true, allowJs: true, checkJs: true). When used with tsc, this will check the code, including the js.
  2. Add a yarn command to trigger the check of the client including the js, but not generate the JS code.
  3. In the webpack.config.js, declare the new tsconfig.json is the configFile to be used. Ask ts-loader to only compile the files which match the rules (and not the full project each time), thanks to onlyCompileBundledFiles: true.

Time gain
On master :

[tonio@zenbook kresus]$ time ./node_modules/.bin/webpack

real	0m17,938s
user	0m32,150s
sys	0m0,816s

On ts-client:

[tonio@zenbook kresus]$ time ./node_modules/.bin/webpack

real	0m14,007s
user	0m25,507s
sys	0m0,726s
Edited by Antoine

Merge request reports

Loading