我有一个与grunt-usemin
插件相关的问题。
基本上,我想把所有静态内容放在app
或dist
目录下的static/
文件夹中(取决于应用是否构建)。
现在,这是我的grunt配置:
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:
{}
但问题在于将普通文件与它们的版本进行替换,例如,在使用usemin之前,下面是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
目录中选择revved文件。
现在,例如将dist/static/login
目录移动到dist/login
并将dirs
更改为dist
,一切正常,因此给dist
子目录似乎会引起问题。