Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the codebase to TypeScript (and compiled to AMD) #66

Open
6 of 10 tasks
ficristo opened this issue Jan 3, 2018 · 0 comments
Open
6 of 10 tasks

Convert the codebase to TypeScript (and compiled to AMD) #66

ficristo opened this issue Jan 3, 2018 · 0 comments

Comments

@ficristo
Copy link
Member

ficristo commented Jan 3, 2018

Some tips to compile to AMD.

Configuration
A minimal tsconfig.json should be:

{
  "compilerOptions": {
    "module": "amd",
    "moduleResolution": "classic"
  }
}
Why commonjs doesn't work

Starting from typescript 2.2, when files are compiled it is added a new statement like
Object.defineProperty(exports, "__esModule", { value: true });.
So a tsconfig file with

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
  }
}

will result in

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
define(function (require, exports, module) {
...
});

which results in runtime error because of the usage of exports outside the define wrapper.


Why the compiled code is not wrapped in a define function?
If a file doesn't have any import statement is not wrapped in a define function, in that case add an empty export.
See microsoft/TypeScript#20943

Import module object
Add this line to be able to use module directly. It is a deprecated syntax but I didn't find anything better.
/// <amd-dependency path="module" name="module"/>

Compatibility TypeScript and RequireJS
Use export = Foo when RequireJS uses module.exports = Foo.


Track of changes

After the merge with Brackets commits:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant