代码之家  ›  专栏  ›  技术社区  ›  Adam Schindler

在浏览器上将AMD键入到单个文件

  •  2
  • Adam Schindler  · 技术社区  · 8 年前

    我正在使用 打字脚本 并使用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);
    });
    

    我该如何让它在浏览器上运行?

    我试着把需求包括在内。但js并没有成功做到这一点。

    我需要把它编译成一个文件,所有的配置都需要在gruntfile上。js因为这将是一个大型项目,将作为 单个文件 .

    还有,有没有更有效的方法不需要第三方库将其编译成一个文件?

    1 回复  |  直到 8 年前
        1
  •  3
  •   basarat    8 年前

    我该如何让它在浏览器上运行?

    您需要使用require。js运行时。AMD需要AMD加载程序,需要。js是最流行的选项。

    更多

    文档 http://requirejs.org/docs/start.html

    个人的

    就我个人而言,我只会将commonjs与Web包结合使用: https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html