Вопрос

In TypeScript, if I am targeting a browser, how does module loading work? Can I use require.js to load modules? does it have it's own loader?

Это было полезно?

Решение

TypeScript does not provide a runtime. You need to supply a module loader to use, such as requirejs. A TypeScript module can either be generated to CommonJS convention (for use with node.js) or AMD convention (as used in requirejs); which it generates is a compiler switch.

Другие советы

As Chuckj mentioned, TypeScript does not provide a runtime. You need to supply a module loader to use.

What you then need to do is to tell the TypeScript compiler to generate the JS to confirm with the module loader that would be used at runtime.

You can do this by specifying the module loader to the compiler using -m compiler flag:

tsc -m commonjs //'amd', 'system', 'umd' or 'es2015'

or by specifying the module in the compilerOptions in your tsconfig.json file:

{
    "compilerOptions": {
        "noImplicitAny": true,
        "module": "commonjs" //'amd', 'system', 'umd' or 'es2015'
    },
    "exclude": [
        "node_modules"
    ]
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top