TypeScript generating wrong JS in Release Mode

寵の児 提交于 2019-12-25 06:23:39

问题


I do not know if this is a known issue. I am working with VS 2012 Web Express with Typescript 0.8.1.1. I am using the --module AMD clause to generate AMD modules.

Iin Debug mode the compiler generates a define clause like this:

define(["require", "exports", "app/Config", "app/ModelLocator", "app/Presenter", "app/Messenger", "app/LogOnWindow", "app/vm/VmAppHeader", "app/framework/PageLocator", "app/framework/ViewStacks"], function(require, exports, __cfg__, __ml__, __pr__, __ms__, __rc__, __lw__, __ah__, __pl__, __vs__) ...

When I compile in Release mode the generated code is this:

var cfg = require("./app/Config")
var ml = require("./app/ModelLocator")
var pr = require("./app/Presenter")
var ms = require("./app/Messenger")
var rc = require("./app/RouteConfig")
var lw = require("./app/LogOnWindow")
var ah = require("./app/vm/VmAppHeader")
var pl = require("./app/framework/PageLocator")
var vs = require("./app/framework/ViewStacks")

That is in Release mode it is generating code for CommonJS modules and not AMD modules.

Is there a way to make it work ???

Thanks in advance


回答1:


I'm guessing you did this:

  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptSourceMap> --sourcemap --module amd</TypeScriptSourceMap>
  </PropertyGroup>

Note that this block only gets included in the Debug configuration. What you want to do instead is move the --module amd thing lower in the file where the compiler is invoked.

  <Target Name="BeforeBuild">
    <Message Text="Compiling TypeScript files" />
    <Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc$(TypeScriptSourceMap) --module amd @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
  </Target>


来源:https://stackoverflow.com/questions/14245182/typescript-generating-wrong-js-in-release-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!