0

这是我的输入文件(使用 yeoman-angular)

  <!-- build:js(./) scripts/vendor.js -->
  <!-- bower:js -->
  <script src="bower_components/angular/angular.js"></script>
  ...
  <script src="bower_components/pagedown-semantic-ui/pagedown.js"></script>
  <!-- endbower -->
  <!-- endbuild -->

并且 usemin 编译一个signle文件中的所有文件vendor.xxxx.js并将html替换为:

<script src="scripts/vendor.f5d9f6b9.js"></script>

但是这里的路径是相对的,我想要一个绝对路径。此外,角度应用程序位于我的节点服务器的子目录中(在仪表板/中),因此我正在使用 nignx 并重定向必要的内容。我想要:

<script src="/dashboard/scripts/vendor.f5d9f6b9.js"></script>

但是脚本文件本身应该保持不变。

4

1 回答 1

4

您的问题与 usemin 有关,请参阅此处的文档:https ://github.com/yeoman/grunt-usemin

只需将 index.html 中的注释替换为:

<!-- build:js(./) /dashboard/scripts/vendor.js -->

意思是:

<!-- build:PATH_WHERE_TO_FIND_FILES DESTINATION_PATH -->

用 ngAnnotate 替换 ngmin:

修改你的 Gruntfile:

代替:

// ngmin tries to make the code safe for minification automatically by
// using the Angular long form for dependency injection. It doesn't work on
// things like resolve or inject so those have to be done manually.
ngmin: {
  dist: {
    files: [{
      expand: true,
      cwd: '.tmp/concat/scripts',
      src: '*.js',
      dest: '.tmp/concat/scripts'
    }]
  }
},

经过

ngAnnotate: {
    options: {
        singleQuotes: true
    },
    dist: {
        files: [{
            expand: true,
            cwd: '.tmp/concat/scripts',
            src: '*.js',
            dest: '.tmp/concat/scripts'
        }]
    }
},

并替换:

grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngmin',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
]);

经过:

grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngAnnotate',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
]);

运行这两个命令来修改你的 package.json: 1. npm uninstall grunt-ngmin --save 2. npm install grunt-ng-annotate --save

于 2014-08-20T11:19:01.653 回答