我正在使用 yeoman 和 grunt 来构建我的项目和 grunt-css 插件,用于使用 grunt.js 内置的“cssmin”而不是“css”
索引.html
<!-- build:css styles/styles.css -->
<link rel="stylesheet" href="styles/main.css"/>
<!-- endbuild -->
<!-- build:js scripts/scripts.js -->
<script src="scripts/vendor/jquery.min.js"></script>
<script src="scripts/vendor/handlebars-1.0.0.beta.6.js"></script>
<script src="scripts/vendor/ember-1.0.pre.min.js"></script>
<script src="scripts/main.js"></script>
<script src="scripts/routes/app-router.js"></script>
<script src="scripts/store.js"></script>
<script src="scripts/controllers/application-controller.js"></script>
<script src="scripts/models/application-model.js"></script>
<script src="scripts/views/application-view.js"></script>
<!-- endbuild -->
Gruntfile.js
rev: {
js: 'dist/scripts/**/*.js', // scripts/**/*.js
css: 'dist/styles/**/*.css', // styles/**/*.css
img: 'dist/images/**' // images/**
},
'usemin-handler': {
html: 'index.html'
},
usemin: {
html: ['dist/**/*.html'], // **/*.html
css: ['dist/**/*.css'] // **/*.css
},
rjs: {
// no minification, is done by the min task
optimize: 'none',
baseUrl: './scripts',
wrap: true
},
cssmin: {
dist: {
src: [
'app/styles/**/*.css'
],
dest: 'dist/styles/styles.css'
}
},
concat: {
dist: {
src: [
'app/scripts/**/*.js'
],
dest: 'dist/scripts/scripts.js',
separator: '/**********/\n'
}
},
min: {
dist: {
src: [
'dist/scripts/scripts.js'
],
dest: 'dist/scripts/scripts.js',
separator: '/**********/\n'
}
}
那么构建项目结构是:
dist/
|__scripts/
|____04216377.scripts.js
|__styles/
|____d41d8cd9.styles.css
|__index.html
然后输出 index.html 文件
<link rel="stylesheet" href="styles/styles.css"/?>
<script src="scripts/04216377.scripts.js"></script>
如您所见,除了重命名 index.html 中应为'styles/d41d8cd9.styles.css 的修订后的样式外,一切正常。有人知道为什么吗?问号是“?” 在行正常???
注意:有关更多信息,这将在我的控制台中输出(无错误)运行“rev:js”(rev)任务 dist/scripts/scripts.js --- 04216377.scripts.js
运行 "rev:css" (rev) 任务 dist/styles/styles.css --- d41d8cd9.styles.css
运行“rev:img”(rev) 任务
运行“usemin:html”(usemin)任务
usemin:html - dist/index.html 脚本/scripts.js
was <script src="scripts/scripts.js"></script>
now <script src="scripts/04216377.scripts.js"></script>
运行“usemin:css”(usemin)任务
usemin:css - dist/styles/d41d8cd9.styles.css
并且没有重命名!非常感谢你们!