Grunt-usemin和revved文件 - dirs选项

时间:2013-11-06 18:59:55

标签: node.js gruntjs grunt-usemin

我的grunt-usemin插件存在问题。

基本上,我想将所有静态内容放在static/app下的dist目录中(取决于是否构建了应用程序)。

现在,这是我的咕噜声配置

useminPrepare: {
  html: ['<%= yeoman.app %>/app.html', '<%= yeoman.app %>/login.html'],
  options: {
    dest: '<%= yeoman.dist %>/static'
  }
},
usemin: {
  html: ['<%= yeoman.dist %>/{,*/}*.html'],
  css: ['<%= yeoman.dist %>/static/styles/**/*.css'],
  options: {
    dirs: ['dist/static/']
  }
}

第一部分可以在输出上观看

Found a block:
    <!-- build:css(.tmp) login/styles/main.css -->
    <link rel="stylesheet" href="styles/bootstrap.css">
    <link rel="stylesheet" href="styles/main.css">
    <!-- endbuild -->
Updating config with the following assets:
    - .tmp/styles/bootstrap.css
    - .tmp/styles/main.css

Found a block:
    <!-- build:js({app/static}) login/scripts/libs.js -->
    <script src="bower_components/angular/angular.js"></script>
    <!-- endbuild -->
Updating config with the following assets:
    - {app/static}/bower_components/angular/angular.js

Found a block:
    <!-- build:js({.tmp,app/static}) login/scripts/scripts.js -->
    <script src="scripts/loginApp.js"></script>
    <script src="scripts/controllers/login.js"></script>
    <!-- endbuild -->
Updating config with the following assets:
    - {.tmp,app/static}/scripts/loginApp.js
    - {.tmp,app/static}/scripts/controllers/login.js

Configuration is now:

  cssmin:
  { 'dist/static/login/styles/main.css': 'dist/static/login/styles/main.css' }

  concat:
  { 'dist/static/login/styles/main.css': 
   [ '.tmp/styles/bootstrap.css',
     '.tmp/styles/main.css' ],
  'dist/static/login/scripts/libs.js': [ '{app/static}/bower_components/angular/angular.js' ],
  'dist/static/login/scripts/scripts.js': 
   [ '{.tmp,app/static}/scripts/loginApp.js',
     '{.tmp,app/static}/scripts/controllers/login.js' ] }

  uglify:
  { 'dist/static/login/scripts/libs.js': 'dist/static/login/scripts/libs.js',
  'dist/static/login/scripts/scripts.js': 'dist/static/login/scripts/scripts.js' }

  requirejs:
  {}

但问题是将普通文件与其加速版本进行交换,例如,在使用之前这是html:

<!doctype html>
<html class="no-js">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Login</title>
    <meta name="viewport" content="width=device-width">
    <!-- build:css(.tmp) login/styles/main.css -->
    <link rel="stylesheet" href="styles/bootstrap.css">
    <link rel="stylesheet" href="styles/main.css">
    <!-- endbuild -->
</head>
  <body ng-app="jsLinkedinConnectorLoginApp">
    <div class="container" ng-view=""></div>

    <!-- build:js({app/static}) login/scripts/libs.js -->
    <script src="bower_components/angular/angular.js"></script>
    <!-- endbuild -->

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

之后:

<!doctype html>
<html class="no-js">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Login</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="login/styles/main.css">
</head>
  <body ng-app="jsLinkedinConnectorLoginApp">
    <div class="container" ng-view=""></div>

    <script src="login/scripts/libs.js"></script>

    <script src="login/scripts/scripts.js"></script>
  </body>
</html>

所以它几乎是正确的,似乎grunt没有在dist/static目录中获取转换文件。

现在,当我将dist/static/login目录向上移动到dist/login并将dirs更改为dist时,一切正常,因此将子目录提供给dist似乎会引起问题。

1 个答案:

答案 0 :(得分:2)

我通过将grunt-usemin插件更新为2.0.0版本并将dirs属性切换为assetsDirs来解决了我的问题。