Mystery Master | Build JavaScript Files | Member |
---|
This metawork article explains how I build the JavaScript files. TypeScript does not run in the browser; JavaScript does. That is why TypeScript has to be transpiled into JavaScript. This process references a tsconfig.json
file (if it exists) which specifies root files and options to compile the project. The folder containing the tsconfig.json
file is considered the root of a TypeScript project. For my development computer, this folder is:
C:/projects/mysterymaster.com/ts
I want the resultant JavaScript to (1) run in a browser such as Google's Chrome (client), and (2) on my development computer under Node.js (server). I haven't figured that out yet, so I need two config files. When I am compiling with one of them, the other has to be renamed. The names I use are tsconfig-client.json
(browser) and tsconfig-server.json
(Node.js).
Browser (Client) | Node.js (Server) |
---|---|
{ "compilerOptions": { "module": "es6", "outDir": "../js", "lib": [ "es6","dom" ], "target": "es6", "noImplicitAny": true, "removeComments": true, "rootDir": "./" }, "exclude": [ "node_modules", "server" ] } |
{ "compilerOptions": { "module": "commonjs", "outDir": "../metawork/js", "lib": [ "es6","dom" ], "target": "es6", "noImplicitAny": true, "removeComments": true, "rootDir": "./" }, "exclude": [ "node_modules" ] } |
The important difference is the "module" option.
When I compile for the browser, the module is set to "es6", and output goes to the mysterymaster.com/js
folder.
When I compile for Node.js, the module is set to "commonjs", and output goes to the mysterymaster.com/metawork/js
folder.