4

I have been looking at using TypeScript and Browserify together. What I can't understand is that they both use require. TS uses require to require other TS modules. Browserify uses requires to find other js files.

So the thing I can't understand here is that I would have to pass it through 2 compilation stages. 1 stage would compile TS to JS (with Browserfiy requires still left in). And 2nd stage would convert JS (with Browserify) to 1 big file reading for production.

How do these compilers above, know the difference between a require for Browserify and a require for TypeScript ?

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin
  • 23,844
  • 55
  • 201
  • 327
  • 2
    I cannot answer your question, but an interesting module to look at might be [tsify](https://www.npmjs.com/package/tsify). – Daniel B Nov 19 '15 at 14:56

1 Answers1

3

TypeScript compiler (tsc) parses the following require syntax:

import m = require("mod");

whereas normally you just write

var m = require("mod");

The later syntax is not checked by tsc more in-depth - it's just a simple assignment for tsc. The former one is checked by tsc to verify that mod is a module written in TypeScript (example)

Community
  • 1
  • 1
MartyIX
  • 27,828
  • 29
  • 136
  • 207