2016-06-29 54 views
1

我正在使用TypeScript编写脚本,当我使用browserify进行转换时,我的主变量未在浏览器中找到。浏览器中找不到Browserify全局变量

main.ts

import { GameSmart } from './GameSmart'; 

const gamesmart = new GameSmart(); 

gulpfile.js

/* require's snipped */ 

gulp.task('build', function() { 
    return browserify() 
     .add('./src/gamesmart/main.ts') 
     .plugin(tsify) 
     .bundle() 
     .on('error', function (error) { 
      console.error(error); 
      throw error; 
     }) 
     .pipe(source('gamesmart.js')) 
     .pipe(gulp.dest('build/')); 
}); 

在我的网页,我包括新创建的文件,并试图调用gamesmart变量,但它是未找到。

<script scr="/path/to/sdk.js"> 
<script> 
    gamesmart.game.started(); 
</script> 

如何将它作为全局/根变量?

回答

1

我能够通过将该变量添加到window来解决此问题。

window['gamesmart'] = new GameSmart(); 
相关问题