2014-01-30 87 views
1

當應用程序處於生產模式時,我需要注入一個angularjs模塊依賴項。我正在使用requirejs來處理腳本加載。RequireJS production/dev variables

目前,我有一些,如果塊安裝在我的asp.net文件中設置像一個全局變量:

@if (!HttpContext.Current.IsDebuggingEnabled){ 
    <script type="text/javascript">window.env = "production";</script> 
} 

,然後在我的javascript我做的:

if(window.env === "production"){ 
    app.requires.push('templates-main'); 
} 

是有一個首選的方法來處理這個?

回答

1

您可能,至少,通過RequireJs優化achive它:

您可以添加到您的構建配置:

pragmas: { 
    production: true 
}, 

//>>includeStart("production", pragmas.production); 
app.requires.push('templates-main') 
//>>includeEnd("production"); 

更多requirejs編譯指示here