TypeScript AMD 到浏览器上的单个文件
TypeScript AMD to single file on browser
我正在使用 TypeScript 并使用 grunt.
使用 AMD 模块将其编译成一个文件到 ES5
例如我有 app.ts
:
import {CONFIG} from './config';
console.log(CONFIG.app)
和config.ts
:
export const CONFIG = {
app : 'MyApp'
}
App是最终需要执行的主脚本,我的构建输出如下:
define("config", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CONFIG = {
app: 'MyApp'
};
});
define("main", ["require", "exports", "config"], function (require, exports, config_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
console.log(config_1.CONFIG.app);
});
我应该如何让它在浏览器上运行?
我试过 require.js 但没有成功。
我需要将它编译成一个文件,所有配置都需要在 gruntfile.js 上,因为它将是一个大型项目,将作为一个 单个文件.
此外,有没有更有效的方法,不需要第三方库将其全部编译到一个文件中?
How am I supposed to make it runnable on a browser ?
您需要使用 require.js 运行时。 AMD 需要 AMD 加载程序,require.js 是最受欢迎的选项。
更多
文档 http://requirejs.org/docs/start.html
个人
就我个人而言,我只会将 commonjs 与 webpack 一起使用:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
我正在使用 TypeScript 并使用 grunt.
使用 AMD 模块将其编译成一个文件到 ES5例如我有 app.ts
:
import {CONFIG} from './config';
console.log(CONFIG.app)
和config.ts
:
export const CONFIG = {
app : 'MyApp'
}
App是最终需要执行的主脚本,我的构建输出如下:
define("config", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CONFIG = {
app: 'MyApp'
};
});
define("main", ["require", "exports", "config"], function (require, exports, config_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
console.log(config_1.CONFIG.app);
});
我应该如何让它在浏览器上运行?
我试过 require.js 但没有成功。
我需要将它编译成一个文件,所有配置都需要在 gruntfile.js 上,因为它将是一个大型项目,将作为一个 单个文件.
此外,有没有更有效的方法,不需要第三方库将其全部编译到一个文件中?
How am I supposed to make it runnable on a browser ?
您需要使用 require.js 运行时。 AMD 需要 AMD 加载程序,require.js 是最受欢迎的选项。
更多
文档 http://requirejs.org/docs/start.html
个人
就我个人而言,我只会将 commonjs 与 webpack 一起使用:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html