3

我正在使用 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

并且没有重命名!非常感谢你们!

4

1 回答 1

5

我发现了问题。我有 Yeoman 0.94 版本,需要修复 usemin 任务。at的?字符<link>是一个正则表达式错误。您应该重写此表达式,因为 css 重命名失败。在https://github.com/yeoman/yeoman/issues/586找到了正确的解决方法

代替

content.replace(block, indent + '<link rel="stylesheet" href="' + target + '"\/?>');

content.replace(block, indent + '<link rel="stylesheet" href="' + target + '"/>');

如果应用更改,则此问题已解决。注意:usemin.js/usr/local/lib/node_modules/yeoman/tasks(在 OSX 上)应用补丁

于 2012-11-16T11:22:36.837 回答