问题
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 ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc$(TypeScriptSourceMap) --module amd @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
来源:https://stackoverflow.com/questions/14245182/typescript-generating-wrong-js-in-release-mode