Grunt构建不会创建css文件

时间:2014-02-06 23:19:51

标签: css angularjs gruntjs compass-sass yeoman

我是Yeoman和Grunt的新手。

在进行Grunt构建时,构建似乎已成功结束,但未创建dist / styles / *。css文件。

从日志中看起来样式被编译为.tmp / styles /(参见下面的“compass:dist”(指南针)任务)但不会被复制或缩小为dist / styles。这就是为什么“usemin:css”(usemin)不存档文件。 - 但这只是猜测。

我正在使用由yeoman生成的基本Gruntfile.info(我在下面添加了它) 我做的唯一改变是注释掉cssmin任务,因为我假设要做same thing

这是构建输出:

$ grunt build
Running "clean:dist" (clean) task
Running "bower-install:app" (bower-install) task

Running "useminPrepare:html" (useminPrepare) task
Going through app/index.html to update the config
Looking for build script HTML comment blocks

Configuration is now:

  concat:
  { generated:
   { files:
      [ { dest: '.tmp\\concat\\scripts\\scripts.js',
          src:
           [ LIBRARIES ] },
        { dest: '.tmp\\concat\\scripts\\modules.js',
          src:
           [ SOURCE ] } ] } }

  uglify:
  { generated:
   { files:
      [ { dest: 'dist\\scripts\\scripts.js',
          src: [ '.tmp\\concat\\scripts\\scripts.js' ] },
        { dest: 'dist\\scripts\\modules.js',
          src: [ '.tmp\\concat\\scripts\\modules.js' ] } ] } }

  cssmin:
  {}

Running "concurrent:dist" (concurrent) task

Running "imagemin:dist" (imagemin) task
? app/images/yeoman.png (saved 9.06 kB)
Minified 1 image (saved 9.06 kB)

Done, without errors.

Running "svgmin:dist" (svgmin) task

Done, without errors.

Running "compass:dist" (compass) task
directory .tmp/styles/
       create .tmp/styles/bootstrap.css (1.759s)
       create .tmp/styles/main.css (0.117s)
       create .tmp/styles/problem-comprehension.css (0.002s)
       create .tmp/styles/problem-timedword.css (0.002s)
       create .tmp/styles/track-detail.css (0.009s)
    Compilation took 1.915s

Done, without errors.

Running "autoprefixer:dist" (autoprefixer) task
Prefixed file ".tmp/styles/bootstrap.css" created.
Prefixed file ".tmp/styles/main.css" created.
Prefixed file ".tmp/styles/problem-comprehension.css" created.
Prefixed file ".tmp/styles/problem-timedword.css" created.
Prefixed file ".tmp/styles/track-detail.css" created.

Running "concat:generated" (concat) task
File ".tmp\concat\scripts\scripts.js" created.
File ".tmp\concat\scripts\modules.js" created.

.
.
.

Running "usemin:html" (usemin) task

Processing as HTML - dist/404.html
Update the HTML to reference our concat/min/revved script files
Update the HTML with the new css filenames
Update the HTML with the new img filenames
Update the HTML with data-main tags
Update the HTML with data-* tags
Update the HTML with background imgs, case there is some inline style
Update the HTML with anchors images
Update the HTML with reference in input
.
All HTML files in the project
.

Running "usemin:css" (usemin) task

Running "htmlmin:dist" (htmlmin) task
File <FILE>.html created.

Done, without errors.


Execution Time (2014-02-06 22:23:38 UTC)
clean:dist         1.3s  ■■■■■■■■■■ 7%
concurrent:dist    5.3s  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 29%
ngmin:dist         2.3s  ■■■■■■■■■■■■■■■■■ 13%
copy:dist          6.1s  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 33%
uglify:generated   2.6s  ■■■■■■■■■■■■■■■■■■■ 14%
usemin:html       349ms  ■■■ 2%
Total 18.4s

来自Grunt.js的构建目标:

grunt.registerTask('build', [
    'clean:dist',
    'bower-install',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngmin',
    'copy:dist',
    'cdnify',
//    'cssmin',
    'uglify',
    'rev',
    'usemin',
    'htmlmin'
  ]);

干杯!

3 个答案:

答案 0 :(得分:10)

您的HTML中可能存在问题,可能您忘记为grunt任务添加注释。

<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- endbuild -->

答案 1 :(得分:8)

开箱即用的Yeoman需要根据我的经验进行一些调整。这是Grunt引擎真的想要缩小一些东西 - 这是它的主要增值之一。我也很陌生,但我想在grunt文件中空的cssmin区域会让你感到烦恼。尝试将这样的东西放到gruntfile.js的cssmin区域 -

    cssmin: {
        dist: {
            files: {
                '<%= yeoman.dist %>/styles/main.css': [
                    '.tmp/styles/{,*/}*.css',
                    '<%= yeoman.app %>/styles/{,*/}*.css'
                ]
            }
        }
    },

那你应该给你的css缩小一些牙齿。然后,您将在gruntfile.js底部的构建任务中取消注释cssmin,以便在CLI上执行'grunt build'时运行。

答案 2 :(得分:0)

我尝试了这里解释的所有选项,但没有一个适合我。在我的案例中解决了这个问题:用SCSS扩展名命名你的文件,作为main.scss文件,例如: custom.scss位于&lt;%= yeoman.app%&gt; / styles / folder。