読者です 読者をやめる 読者になる 読者になる

Milk+ea

Weblog Is My Hobby.

Gruntfile.coffee

整理整㌧。

追記ついでに修正

module.exports = (grunt) ->
  require('load-grunt-tasks')(grunt)
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'

    dir:
      dev:
        root: 'dev'
        img: 'dev/img'
        font: 'dev/css/font'
        css: 'dev/css'
        sass: 'dev/sass'
        js: 'dev/js'
        coffee: 'dev/coffee'
        icon: 'dev/icon'
        lib: 'dev/lib'
      build:
        root: 'build'
        img: 'build/img'
        css: 'build/css'
        js: 'build/js'
        icon: 'build/icon'
      tmp:
        css: '.tmp/css'
      config: 'config'

    connect:
      options: port: 8080
      dev: options: base: '<%= dir.dev.root %>'
      build: options: base: '<%= dir.build.root %>'

    clean:
      build: ['<%= dir.build.root %>/*.html', '<%= dir.build.css %>/*.css', '<%= dir.build.js %>/*.js']

    copy:
      build: files: [
        { expand: true, src: ['<%= dir.dev.root %>/*'], dest: '<%= dir.build.root %>', filter: 'isFile', flatten: true}
        { expand: true, src: ['<%= dir.dev.icon %>/*'], dest: '<%= dir.build.icon %>', filter: 'isFile', flatten: true }
      ]

    concat:
      bower: files: [
        { src: '<%= dir.dev.lib %>/**/*.js', dest: '<%= dir.dev.js %>/lib.js' }
        { src: '<%= dir.dev.lib %>/**/*.css', dest: '<%= dir.dev.css %>/b4.css' }
      ]

    compress:
      options: mode: 'gzip'
      html: { expand: true, src: '<%= dir.build.root %>/*.html', ext: '.html.gz' }
      css: { expand: true , src: '<%= dir.build.css %>/*.css', ext: '.css.gz' }
      js: { expand: true, src: ['<%= dir.build.js %>/*.js', '!<%= dir.build.js %>/*.ng.js'], ext: '.js.gz' }
      ng: { expand: true, src: '<%= dir.build.js %>/*.ng.js', ext: '.ng.js.gz' }

    'ftp-deploy':
      sakura:
        auth:
          host: 'user.sakura.ne.jp'
          port: 21
          authKey: 'Sakura'
        src: '<%= dir.build.root %>'
        dest: 'home/user/www/'
        exclusions: ['']

    useminPrepare:
      html: '<%= dir.dev.root %>/index.html'
      options:
        root: '<%= dir.dev.root %>'
        dest: '<%= dir.build.root %>'
        flow: { steps: { css: ['concat'], js: ['concat'] }, post: {} }

    usemin:
      html: '<%= dir.build.root %>/index.html'

    imagemin:
      build: files: [
        expand: true
        cwd: '<%= dir.dev.img %>'
        src: ['**/*.{png,jpg,jpeg,gif}']
        dest: '<%= dir.build.img %>'
      ]

    htmlmin:
      options:
        removeComments: true
        collapseWhitespace: true
        collapseBooleanAttributes: true
        minifyJS: true
        minifyCSS: true
      build: { expand: true, src: ['<%= dir.build.root %>/**/*.html'] }

    compass:
      auto: options: config: '<%= dir.config %>/config.rb'

    autoprefixer:
      options: browsers: ['> 1%', 'last 2 versions']
      auto: { expand: true, src: ['<%= dir.tmp.css %>/*.css'], dest: '<%= dir.dev.css %>', flatten: true}
    cmq:
      options: log: true
      build: { expand: true, src: ['<%= autoprefixer.auto.dest %>/**/*.css', '!<%= autoprefixer.auto.dest %>/**/moz.css'] }
    uncss:
      options:
        ignore: []
        stylesheets: ['css/b4.css']
      files: { src: ['<%= dir.dev.root %>/**/index.html'], dest: '<%= dir.dev.css %>/b4.css' }
    csscomb:
      build: { expand: true, src: ['<%= dir.build.css %>/**/*.css'] }
    csso:
      build: { expand: true, src: ['<%= csscomb.build.src %>'] }
    coffee:
      no:
        expand: true
        src: ['<%= dir.dev.coffee %>/**/*.coffee', '!<%= dir.dev.coffee %>/**/*.ng.coffee']
        dest: '<%= dir.dev.js %>'
        ext: '.js'
        flatten: true
      ng:
        expand: true
        src: '<%= dir.dev.coffee %>/**/*.ng.coffee'
        dest: '<%= dir.dev.js %>'
        ext: '.ng.js'
        flatten: true
    ngmin:
      build: { expand: true, src: '<%= coffee.ng.dest %>/**/*.ng.js' }
    uglify:
      no: { expand: true, cwd: '<%= coffee.no.dest %>', src: ['**/*.js', '!**/*.ng.js'], dest: '<%= coffee.no.dest %>' }
      ng:
        options: mangle: false
        files: [{ expand: true, src: '<%= coffee.ng.dest %>/**/*.ng.js' }]


    watch:
      livereload:
        options: livereload: true
        files: ['<%= dir.dev.root %>/**/*.html', '<%= dir.dev.css %>/**/*.css', '<%= dir.dev.js %>/**/*.js']
      sass: { files: ['<%= dir.dev.sass %>/*.sass'], tasks: 'compass' }
      css: { files: ['<%= autoprefixer.auto.src %>'], tasks: 'autoprefixer' }
      coffee: { files: ['<%= coffee.no.src %>'], tasks: 'coffee:no' }
      ng: { files: ['<%= coffee.ng.src %>'], tasks: 'coffee:ng' }

    bower:
      def: options:
        targetDir: '<%= dir.dev.lib %>'
        layout: 'byType'
        install: true
        verbose: false
        cleanTargetDir: true
        cleanBowerDir: false



  grunt.registerTask 'bw', ['bower', 'concat']
  grunt.registerTask 'default', ['connect:dev', 'watch']
  grunt.registerTask 'i', ['bower', 'concat', 'compass', 'autoprefixer', 'coffee']
  grunt.registerTask 'i-w', ['bower', 'concat', 'compass', 'autoprefixer', 'coffee', 'connect:dev', 'watch']
  grunt.registerTask 'i-b', ['bower', 'concat', 'compass', 'autoprefixer', 'coffee', 'uncss', 'cmq', 'ngmin', 'uglify', 'copy', 'useminPrepare', 'concat:generated', 'usemin', 'csscomb', 'csso', 'htmlmin', 'imagemin']
  grunt.registerTask 'i-b-w', ['bower', 'concat', 'compass', 'autoprefixer', 'coffee', 'uncss', 'cmq', 'ngmin', 'uglify', 'copy', 'useminPrepare', 'concat:generated', 'usemin', 'csscomb', 'csso', 'htmlmin', 'imagemin', 'connect:build', 'watch']
  grunt.registerTask 'i-b-s', ['bower', 'concat', 'compass', 'autoprefixer', 'coffee', 'uncss', 'cmq', 'ngmin', 'uglify', 'copy', 'useminPrepare', 'concat:generated', 'usemin', 'csscomb', 'csso', 'htmlmin', 'imagemin', 'compress', 'clean', 'ftp-deploy:sakura']
  grunt.registerTask 'b', ['uncss', 'cmq', 'ngmin', 'uglify', 'copy', 'useminPrepare', 'concat:generated', 'usemin', 'csscomb', 'csso', 'htmlmin', 'imagemin']
  grunt.registerTask 'b-w', ['uncss', 'cmq', 'ngmin', 'uglify', 'copy', 'useminPrepare', 'concat:generated', 'usemin', 'csscomb', 'csso', 'htmlmin', 'imagemin', 'connect:build', 'watch']
  grunt.registerTask 'sakura', ['compress', 'clean', 'ftp-deploy:sakura']

なんでかimageminをインストールするとエラーが出るようになったんですがが。→解決