對於我Gruntfile.js的concat
塊:未捕獲ReferenceError:未定義angular - 腳本加載順序?
concat: {
options: {
stripBanners: false,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
production: {
files: {
'./public/js/build/services.js': ['./public/js/services/*.js'],
'./public/js/build/factories.js': ['./public/js/factories/*.js'],
'./public/js/build/controllers.js': ['./public/js/controllers/*.js'],
'./public/js/build/directives.js': ['./public/js/directives/*.js'],
'./public/js/build/filters.js': ['./public/js/filters/*.js'],
'./public/js/build/plugins.js': ['./public/js/plugins/*.js'],
'./public/js/build/modern-angular.js': [
'./public/bower_components/jquery/dist/jquery.js',
'./public/bower_components/angular-stable/angular.js',
'./public/bower_components/angular-sanitize-stable/angular-sanitize.js'
],
'./public/js/build/old-angular.js': [
'./public/bower_components/jquery-1.11/index.js',
'./public/bower_components/angular-unstable/angular.js',
'./public/bower_components/angular-sanitize-unstable/angular-sanitize.js',
'./public/bower_components/html5shiv/dist/html5shiv.js'
],
'./public/js/build/app.js': [
'./public/js/app.js',
'./public/js/build/services.js',
'./public/js/build/factories.js',
'./public/js/build/controllers.js',
'./public/js/build/directives.js',
'./public/js/build/filters.js',
'./public/js/build/plugins.js'
]
}
}
},
正如你可以告訴我Gruntfile.js,我需要支持舊的,過時的瀏覽器,爲此我必須加載兩個不同Angular的版本取決於瀏覽器。
這裏是我的index.ejs:
<!doctype html>
<html lang="en" class="ng-app:idocs" id="ng-app" ng-app="idocs" xmlns:ng="http://angularjs.org">
<head>
<!-- Omitting to prevent bloating -->
<!--[if lte IE 8]>
<script> var olderIE = true; </script>
<![endif]-->
<script>
if (typeof olderIE === 'undefined') {
// User is using a modern browser, they're awesome.
var script = document.createElement('script');
script.setAttribute('src', '/js/build/modern-angular.js');
document.head.appendChild(script);
}
</script>
<!--[if lte IE 8]>
<script src="/js/build/old-angular.js"></script>
<![endif]-->
</head>
<body data-ng-cloak onload="handleTaggerEvent()">
<!-- Again, omitting -->
<% if(nodeEnv == 'production') { %>
<script src="/js/build/app.js"></script>
<% } else { %>
<script src="/js/build/controllers.js"></script>
<script src="/js/build/directives.js"></script>
<script src="/js/build/factories.js"></script>
<script src="/js/build/filters.js"></script>
<script src="/js/build/plugins.js"></script>
<script src="/js/build/templates.js"></script>
<script src="/js/app.js"></script>
<% } %>
<script src="socket.io/socket.io.js"></script>
<script>
var app = {
// Omitting for brevity
};
// Socket.io stuff
</script>
</body>
</html>
然後在瀏覽器中我出現以下錯誤散落。角出現加載,但角碼後剩下:
我很困惑如何切換的哪些文件通過CONCAT產生,同時運行的呼嚕聲會影響在瀏覽器的腳本的加載順序的順序。另外,當你說「其中一份」時,你指的是什麼? './ public/js/build/app.js'是concat中該文件的唯一發生。 – Scott
從代碼看來,'./public/js/build/*'文件是在angular docs之前和之後創建的。我相信角度文檔之前的那些人正在創建錯誤,因爲瀏覽器順序需要類似於:jquery,angular,angular-sanitize,app.js,工廠 - 過濾器。 – Maximus