LoginSignup
4
4

More than 5 years have passed since last update.

package.jsonとGruntfile.jsのサンプル

Posted at

grunt.jsで、以下のタスクを行うようにするサンプル。
ファイル一式を置いたら、以下のコマンドのみでインストールできる。

npm install

Sass

_files/css/*.scssに変更があれば
resources/css/style.cssにコンパイルしたCSSを自動で出力する

JavaScriptの圧縮

_files/js/*.jsに変更があれば
resources/js/all.jsに圧縮したJSを自動で出力する

{
  "name": "grunt",
  "version": "0.0.0",
  "description": "",
  "main": "Gruntfile.js",

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "devDependencies": {
    "grunt-contrib-sass": "~0.5.1",
    "grunt-contrib-watch": "~0.5.3",
    "grunt": "~0.4.2",
    "grunt-contrib-uglify": "~0.2.7"
  }
}
module.exports = function(grunt) {
"use strict";

  grunt.initConfig({

    sass: {
      dist: {
        options: {
//          style: 'expanded'
          style: 'compressed'
        },
        files: {
          'resources/css/style.css': '_files/sass/style.scss'
        }
      }
    },

    uglify: {
      options: {
        mangle: false,
        //beautify: true
      },
      my_target: {
        files: {
          'resources/js/all.js': [
            '_files/js/jquery.easing.js',
            '_files/js/common.js'
          ]
        }
      }
    },

    watch: {
      uglify: {
        files: [
          '_files/js/*.js'
        ],
        tasks: [
          'uglify'
        ]
      },
      sass: {
        files: [
          '_files/sass/*.scss'
        ],
        tasks: [
          'sass'
        ]
      },
      all: {
        files: [
          '<%= watch.uglify.files %>',
          '<%= watch.sass.files %>'
        ],
        tasks: ['uglify', 'sass']
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask('default', ['watch']);

};
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4