Last active
August 29, 2015 14:07
-
-
Save megurock/4dc332a072b708c09ce7 to your computer and use it in GitHub Desktop.
My gruntfile template #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// see http://qiita.com/shinnn/items/57327006390f2181f550 | |
var licenseRegexp = /^\!|^@preserve|^@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\(c\)|License|Copyright|three\.js/mi; | |
var isLicenseComment = (function() { | |
var _prevCommentLine = 0; | |
return function(node, comment) { | |
if (licenseRegexp.test(comment.value) || | |
comment.line === 1 || | |
comment.line === _prevCommentLine + 1) { | |
_prevCommentLine = comment.line; | |
return true; | |
} | |
_prevCommentLine = 0; | |
return false; | |
}; | |
})(); | |
module.exports = function(grunt) { | |
// load plugins in 'devDependencies' | |
require('load-grunt-tasks')(grunt, { | |
scope: 'devDependencies' | |
}); | |
// | |
grunt.initConfig({ | |
// project configuration | |
project: { | |
src: 'src', | |
dist: 'release' | |
}, | |
connect: { | |
dev: { | |
options: { | |
livereload: true, | |
base: '<%= project.src %>/' | |
} | |
}, | |
release: { | |
options: { | |
livereload: true, | |
base: '<%= project.dist %>/' | |
} | |
} | |
}, | |
watch: { | |
html: { | |
files: '<%= project.src %>/index.html', | |
tasks: '', | |
options: { | |
livereload: true, | |
spawn: false | |
} | |
}, | |
css: { | |
files: '<%= project.src %>/css/main_dev.css', | |
tasks: ['autoprefixer'], | |
options: { | |
livereload: true, | |
spawn: false | |
} | |
} | |
}, | |
jade: { | |
compile: { | |
options: { | |
data: { | |
debug: false | |
}, | |
pretty: true | |
}, | |
files: { | |
"<%= project.src %>/index.html": "<%= project.src %>/index.jade" | |
} | |
} | |
}, | |
autoprefixer: { | |
pc: { | |
options: { | |
browsers: ['last 3 versions', 'ie >= 7'], | |
}, | |
src: '<%= project.src %>/css/main_dev.css', | |
dest: '<%= project.src %>/css/main.css' | |
} | |
}, | |
jshint: { | |
main: { | |
options: { | |
}, | |
src: ['<%= project.src %>/js/main.js'] | |
} | |
}, | |
validation: { | |
options: { | |
reset: grunt.option('reset') || true, | |
stoponerror: false, | |
relaxerror: [] | |
}, | |
files: { | |
src: ['<%= project.src %>/index.html'] | |
} | |
}, | |
csslint: { | |
strict: { | |
options: { | |
import: 2 | |
}, | |
src: ['<%= project.src %>/css/main.css'] | |
}, | |
lax: { | |
options: { | |
import: false | |
}, | |
src: ['<%= project.src %>/css/main.css'] | |
} | |
}, | |
clean: { | |
release: ['<%= project.dist %>'] | |
}, | |
uglify: { | |
options: { | |
preserveComments: isLicenseComment | |
}, | |
targets: { | |
files: { | |
'<%= project.dist %>/js/app.min.js': ['<%= project.src %>/js/main.js'] | |
} | |
} | |
}, | |
copy: { | |
main: { | |
files: [{ | |
encoding: 'shift_jis', | |
expand: true, | |
cwd: '<%= project.src %>', | |
src: ['img/**', 'index.html' ], | |
dest: '<%= project.dist %>', | |
dot: false | |
}] | |
} | |
}, | |
useminPrepare: { | |
html: '<%= project.src %>/index.html', | |
options: { | |
root: '<%= project.src %>', | |
dest: '<%= project.dist %>' | |
} | |
}, | |
usemin: { | |
html: ['<%= project.dist %>/index.html'] | |
}, | |
pngmin: { | |
options: { | |
ext: '.png', | |
force: true | |
}, | |
targets: { | |
src: '<%= project.dist %>/img/*.png', | |
dest: '<%= project.dist %>/img', | |
} | |
}, | |
replace: { | |
js: { | |
src: ['<%= project.dist %>/js/app.min.js'], | |
overwrite: true, | |
replacements: [{ | |
from: /console.log(.*);?/g, | |
to: "" | |
}] | |
} | |
}, | |
nightwatch: { | |
options: { | |
standalone: true, | |
jar_path: "/Users/userName/selenium-server-standalone-2.39.0.jar" | |
} | |
} | |
}); | |
// default task | |
grunt.registerTask('default', ['connect:dev', 'watch']); | |
grunt.registerTask('test', ['jshint', 'validation']); | |
grunt.registerTask('release', ['clean', 'autoprefixer', 'copy', 'useminPrepare', 'concat', 'uglify', 'cssmin', 'usemin', 'pngmin']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment