【问题标题】:Integrating typescript partially, angularjs, grunt部分集成 typescript、angularjs、grunt
【发布时间】:2018-09-26 03:37:58
【问题描述】:

早安,

我想将 typescript 集成到一个使用 grunt 的 angularjs 项目中。我想一步一步地做到这一点,这样就不需要重新编写整个项目。

原因是 1) 提高代码质量,为此使用 typescript 和 linting。 2) 引入模块化,因为当前 .js 文件的大小在增长并且代码变得不那么可读。

目前该项目在以下项目中使用 grunt:

'clean:dist',
    'clean:typescript',
    'ts',
    .......,
    'jsbeautifier',
    'less',
    'useminPrepare',
    'concat',
    'copy:dist',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'

在那个繁重的工作流程中发生的事情是,typescript 部分被编译并且 typescript 构建目录包含在 index.html 文件中。所以'useminPrepare', 'concat', 'copy:dist', 'cssmin', 'uglify', 'filerev', 'usemin',

workflow 将 typescript 代码成功集成到 vendor.js 中。

目前的问题是在浏览器中打开时出现以下错误。

Uncaught ReferenceError: exports is not defined Stack Overflow Problem Thread

但是该线程中的所有建议都没有删除(typescript to )javascript编译代码中的Object.defineProperty(exports, "__esModule", { value: true });

我使用了<script>var exports = {};</script>,然后我得到了Uncaught ReferenceError: module is not defined 错误。注意:我还包括了<script src="bower_components/commonjs/common.js"></script>

所以我的假设是我需要在 'useminPrepare''usemin',不过usemin好像不支持browserify。

所以我的问题:

  1. 我如何摆脱这些错误并将用 typescript 编写的部分合理地集成到包中。
  2. 有任何建议或任何其他可能的途径将 typescript 部分集成到 angularjs 和 grunt 项目中?
  3. 如果我走错了路,这是不可能的,或者太复杂了。您认为还有哪些其他方式可以实现我的目标 1) 和 2)(在顶部)?

非常感谢您的帮助。

干杯, 托比亚斯

【问题讨论】:

    标签: angularjs typescript gruntjs grunt-usemin


    【解决方案1】:

    我在这个问题中找到了答案:TS1148 ~ How to "import" with --module: "none" and typescricpt 2.x

    1. 使用"module": "none"
    2. 使用全局 d.ts 文件,如 上面的链接。
    3. 使用 grunt 和 usemin。放一个 glob 模式 (通配符)到您的 html 文件中以包含编译的打字稿 文件<script src="xyz/build/tsc/**/*.js"></script>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-19
      • 2014-03-12
      • 1970-01-01
      • 2018-03-20
      • 2017-09-30
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多