nodejs / grunt usemin插件

时间:2012-11-15 18:56:24

标签: node.js gruntjs yeoman grunt-usemin

我使用自耕农和咕噜来构建我的项目和grunt-css插件,以便使用' cssmin'而不是' css'内置grunt.js

的index.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中应该是&style; styles / d41d8cd9.styles.css的修改后的样式外,一切正常 谁知道为什么? 问号是&#39;?&#39;在线正常???


注意:有关详细信息,请在我的控制台中输出(无错误) 跑步&#34; rev:js&#34; (转)任务 dist / scripts / scripts.js --- 04216377.scripts.js

跑步&#34; rev:css&#34; (转)任务 dist / styles / styles.css --- d41d8cd9.styles.css

跑步&#34; rev:img&#34; (转)任务

运行&#34; usemin:html&#34; (usemin)任务

usemin:html - dist / index.html 脚本/ scripts.js中

was <script src="scripts/scripts.js"></script>
now <script src="scripts/04216377.scripts.js"></script>

运行&#34; usemin:css&#34; (usemin)任务

usemin:css - dist / styles / d41d8cd9.styles.css

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

1 个答案:

答案 0 :(得分:5)

我发现了问题。 我有Yeoman 0.94版本,需要修复usemin任务。 ?处的<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上)

上应用补丁