我的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
似乎会引起问题。
答案 0 :(得分:2)
我通过将grunt-usemin
插件更新为2.0.0
版本并将dirs
属性切换为assetsDirs
来解决了我的问题。