2016-06-29 56 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(); 
相關問題