Ensure webpack does not try to transpile server files. Fixes #1016
This MR provides a tsconfig.json
file for the client.
What are the problems ?
- The way
ts-loader
is currently configured, makes it impossible to transpile.ts
code insideclient/
, because the loader implicitly uses thetsconfig.json
at the root of the project, which excludes theclient/
directory, and includesserver/
(this is the cause of #1016 (closed)).
How to fix : create a proper tsconfig.json file for the client. - 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. - If we activate
checkJs
option, the transpiler also checksnode_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 usecheckJs
withtsc
directly).
My proposal
- Create a
tsconfig.json
for the client which could be use directly bytsc
(withnoEmit: true
,allowJs: true
,checkJs: true
). When used withtsc
, this will check the code, including the js. - Add a yarn command to trigger the check of the client including the js, but not generate the JS code.
- In the
webpack.config.js
, declare the newtsconfig.json
is the configFile to be used. Askts-loader
to only compile the files which match the rules (and not the full project each time), thanks toonlyCompileBundledFiles: 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