2

我的index.html有:

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->


    <link rel="stylesheet" href="/public/stylesheets/bootstrap.css">
    <link rel="stylesheet" href="styles/main.css">
  </head>
  <body ng-app="WebApp">
    <base href="/app">
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

    <!--[if lt IE 9]>
      <script src="bower_components/es5-shim/es5-shim.js"></script>
      <script src="bower_components/json3/lib/json3.min.js"></script>
    <![endif]-->

    <!-- Add your site or application content here -->
    <div class="container" ng-view=""></div>

    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
     <script>
       (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
       (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
       m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
       })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

       ga('create', 'UA-XXXXX-X');
       ga('send', 'pageview');
    </script>

    <script src="/app/bower_components/angular/angular.js"></script>
    <!-- build:js /app/scripts/angular.js -->
    <script src="/app/bower_components/angular-route/angular-route.js"></script> 
    <script src="/app/bower_components/angular-resource/angular-resource.js"></script>
    <script src="/app/bower_components/angular-cookies/angular-cookies.js"></script>
    <script src="/app/bower_components/angular-sanitize/angular-sanitize.js"></script>
    <!-- endbuild -->

    <!-- build:js({.tmp,app}) /app/scripts/scripts.js -->
    <script src="/app/scripts/app.js"></script>
    <script src="/app/scripts/controllers/main.js"></script>
    <!-- endbuild -->
</body>
</html>

我所有的角度代码都在app顶层的目录中。我Gruntfile.coffee的是:

useminPrepare:
  html: "<%= appConfig.app %>/index.html"
  options:
    dest: "<%= appConfig.dist %>"

usemin:
  html: "<%= appConfig.dist %>/*.html"
  css: ["<%= appConfig.dist %>/styles/**/*.css"]
  options:
    dirs: ["<%= appConfig.dist %>"]

但我收到一个错误:

Running "useminPrepare:html" (useminPrepare) task
Going through app/index.html to update the config
Looking for build script HTML comment blocks
Warning: An error occurred while processing a template (Cannot read property 'src' of undefined). Use --force to continue.

我究竟做错了什么?

4

2 回答 2

1

如果我理解正确,您的 index.html 文件位于app目录中,因此您可以尝试在 html 中使用指向脚本的相对链接。

<!-- build:js scripts/angular.js -->
<script src="bower_components/angular-route/angular-route.js"></script> 
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<!-- endbuild -->
于 2013-11-19T06:28:12.043 回答
1

我认为您的问题是,您想连接/缩小角度源。记录的方法是使用提供的文件,如 angular-route.min.js 并将它们包含在 html 的 head 部分中。

因此,以下行会引发该错误:

<script src="/app/bower_components/angular/angular.js"></script>
<!-- build:js /app/scripts/angular.js -->
<script src="/app/bower_components/angular-route/angular-route.js"></script> 
<script src="/app/bower_components/angular-resource/angular-resource.js"></script>
<script src="/app/bower_components/angular-cookies/angular-cookies.js"></script>
<script src="/app/bower_components/angular-sanitize/angular-sanitize.js"></script>
<!-- endbuild -->

附带说明:这些 Angular 库在某些部分包含繁重的复杂源代码,准确配置您的个人压缩器是一个相当大的挑战,就像 Angular 开发人员对他们所做的那样,以提供公共的 angular-xxxxx.min.js 文件。

于 2013-11-17T07:44:52.197 回答