What is the modulation history for TypeScript in a browser?

I am new to browser development, so I have no experience with AMD, CommonJS, UMD, Browserify, RequireJS, etc. I read a lot about them, and I believe that I generally understand the history of JavaScript, but I'm still very confused about how to do everything together.

I have a library written in TypeScript. This is a pure TypeScript library, it does not interact with a browser or browser map, as well as with any node or NPM things.

I also have a TypeScript client application that uses this library. The client application can also use a web structure (e.g. jQuery).

Now, when I compile my two TypeScript files (which we will assume are in separate projects, isolated from each other and built separately), each of them will generate a .js file. In Visual Studio, I need to select AMD or Common as my module loader.

Things are falling apart here. My research tells me that if I want to work on the Internet, I need to either use Browserify or RequireJS. To view the browser, you must first install node on my computer, and then use the command line tool as a post-build step to create the file, and as far as I can tell, this is not available as a NuGet package. Alternatively, I can use RequireJS, but then all the examples stop working. Something is not about doing something on the loading window and instead doing something elsewhere, but nothing that I found really explains well.

, ? TypeScript, , , - , Microsoft.

+4
3

TypeScript AMD CommonJS , JavaScript. . , gulp-typescript, , , AMD/CommonJS JavaScript.

TypeScript . , AMD . CommonJS / browserify, .

, , , JS- TypeScript - . () - , ​​ AMD/CommonJS, JS, , node. , , AMD/CommonJS .

TL; DR: TypeScript, , , AMD/CommonJS. - . , , .

+3

TypeScript JavaScript, - JS, .NET Microsoft.

TypeScript AMD, AMD, RequireJS ( Dojo, curl) HTML , ( RequireJS):

<!DOCTYPE html>
<title>Application name</title>
<script src="scripts/require.js" data-main="scripts/client"></script>

(, TypeScript scripts/client.js.)

RequireJS Dojo AMD - , , AMD .

+2

C Snover, , , - " ". "AMD" "CommonJS".

- , , /, .

, , , ; TypeScript .

You can convert the external module back to the internal module, omitting any export instructions of the module itself (and also without an operator export =at the end of the file). For example, this is an internal module:

module MyLibrary {
  export class MyClass {
    public Foo = 1;    
  }
}

If you use internal modules, all you have to do is specify them in the correct order using the script tags in your HTML files, and they will work without having to deal with any loader system.

<script src="MyLibrary.js"></script>
<script src="MyUICode.js"></script>
+2
source

All Articles