Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Created August 14, 2014 11:27
Show Gist options
  • Save naoyeye/2ca650208f65ef798c89 to your computer and use it in GitHub Desktop.
Save naoyeye/2ca650208f65ef798c89 to your computer and use it in GitHub Desktop.
var lrSnippet = require('connect-livereload')();
var rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest;
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
module.exports = function (grunt) {
require('time-grunt')(grunt);
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var pathConfig = {
app: 'app',
dist: 'dist',
tmp: '.tmp',
test: 'test'
};
grunt.initConfig({
paths: pathConfig,
watch: {
compass: {
files: ['<%= paths.app %>/compass/{,*/}*/{,*/}*.{scss,sass,png,ttf}'],
tasks: ['compass:server']
},
stencil: {
files: ['<%= paths.app %>/**/*.html'],
tasks: ['stencil:server'],
options: {
spawn: false
}
},
statics: {
files: ['<%= paths.app %>/statics/**/*.*'],
tasks: ['copy:server'],
options: {
spawn: false
}
},
jade: {
files: ['<%= paths.app %>/statics/**/*.jade'],
tasks: ['jade:server'],
options: {
spawn: false
}
},
livereload: {
files: [
'<%= paths.app %>/javascripts/**/*.js',
'<%= paths.app %>/images/**/*.*',
'<%= paths.tmp %>/**/*.html',
'<%= paths.tmp %>/stylesheets/**/*.css',
'<%= paths.tmp %>/images/**/*.*'
],
options: {
livereload: true,
spawn: false
}
}
},
connect: {
options: {
port: 9997,
hostname: '0.0.0.0'
},
rules: [{
from: '^/2013_people',
to: '/2013rewind/people.html'
}, {
from: '^/m_terms',
to: '/mobile/terms.html'
}, {
from: '^/m_book_legal',
to: '/mobile/book_legal.html'
}, {
from: '^/m_video_legal',
to: '/mobile/video_legal.html'
}, {
from: '^/m_wallpaper_legal',
to: '/mobile/wallpaper_legal.html'
}, {
from: '^/m_intellectual_property',
to: '/mobile/intellectual-property.html'
}, {
from: '^/user/([0-9]*)$',
to: '/user/index.html'
}],
server: {
options: {
middleware: function (connect) {
return [
// lrSnippet,
rewriteRulesSnippet,
mountFolder(connect, pathConfig.tmp),
mountFolder(connect, pathConfig.app)
];
}
}
}
},
open: {
server: {
path: 'http://127.0.0.1:<%= connect.options.port %>',
app: 'Google Chrome Canary'
}
},
clean: {
dist: ['<%= paths.tmp %>', '<%= paths.dist %>'],
server: {
src: ['<%= paths.tmp %>/*', '!<%= paths.tmp %>/images/**', '!<%= paths.tmp %>/stylesheets/**']
}
},
useminPrepare: {
html: ['<%= paths.tmp %>/**/*.html'],
options: {
dest: '<%= paths.dist %>'
}
},
usemin: {
html: ['<%= paths.dist %>/**/*.html'],
options: {
assetsDirs: ['<%= paths.dist %>'],
root: '<%= paths.tmp %>',
dirs: ['<%= paths.dist %>']
}
},
htmlmin: {
options: {
collapseWhitespace: true
},
dist: {
files: [{
expand: true,
cwd: '<%= paths.dist %>',
src: ['**/*.html'],
dest: '<%= paths.dist %>'
}]
}
},
copy: {
server: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>/statics/',
dest: '<%= paths.tmp %>',
src: [
'**/*.*'
]
}]
},
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>',
dest: '<%= paths.dist %>',
src: [
'images/**/*.{webp,gif,png,jpg,jpeg,ico,otf,ttf,svg}',
'*.ico'
]
}]
},
components: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>',
dest: '<%= paths.dist %>',
src: [
'components/**/*.{css,gif,png,jpg,jpeg,ttf,svg,woff,eot,otf,swf,svg}'
]
}]
},
js: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>',
dest: '<%= paths.tmp %>',
src: [
'**/*.js'
]
}]
},
html: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.tmp %>',
dest: '<%= paths.dist %>',
src: [
'**/*.html'
]
}]
},
oldStyles: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>/_style/',
dest: '<%= paths.dist %>/style/',
src: [
'**/*.*'
]
}]
},
statics: {
files: [{
expand: true,
dot: true,
cwd: '<%= paths.app %>/statics/',
dest: '<%= paths.dist %>',
src: [
'**/*.{html,js,css,gif,png,jpg,jpeg,json,txt,alfredworkflow,ttf,svg,woff}'
]
}]
}
},
compass: {
options: {
sassDir: '<%= paths.app %>/compass/sass',
cssDir: '<%= paths.tmp %>/stylesheets',
imagesDir: '<%= paths.app %>/compass/images',
fontsDir: '/images/fonts',
relativeAssets: true
},
server: {
options: {
generatedImagesDir: '<%= paths.tmp %>/images',
debugInfo: true
}
},
dist: {
options: {
generatedImagesDir: '<%= paths.dist %>/images',
outputStyle: 'compressed',
httpGeneratedImagesPath: '/images/',
relativeAssets: false
}
}
},
rev: {
dist: {
files: {
src: [
'<%= paths.dist %>/javascripts/**/*.js',
'<%= paths.dist %>/stylesheets/**/*.css'
]
}
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= paths.dist %>/images',
src: '**/*.{png,jpg,jpeg}',
dest: '<%= paths.dist %>/images'
}]
}
},
jade: {
server: {
files: {
'<%= paths.app %>/statics/campaign/doraemon2014/': ['<%= paths.app %>/statics/campaign/doraemon2014/src/*.jade']
},
options: {
client: false,
runtime: false,
wrap: false // or 'none'
}
}
},
requirejs: {
dist: {
options: {
optimize: 'uglify',
uglify: {
toplevel: true,
ascii_only: false,
beautify: false
},
preserveLicenseComments: true,
useStrict: false,
wrap: true
}
}
},
concurrent: {
server: {
tasks: ['copy:server', 'compass:server'],
options: {
logConcurrentOutput: true
}
},
staging: {
tasks: ['copy:dist', 'compass:dist', 'copy:statics', 'copy:oldStyles', 'copy:js'],
options: {
logConcurrentOutput: true
}
},
dist: {
tasks: ['copy:dist', 'compass:dist', 'copy:js'],
options: {
logConcurrentOutput: true
}
}
},
jshint: {
test: ['<%= paths.app %>/javascripts/**/*.js']
},
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: [],
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['-a'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: false
}
},
stencil: {
options: {
partials: '<%= paths.app %>/partials',
templates: '<%= paths.app %>/templates',
dot_template_settings: {
strip: false
}
},
server: {
options: {
env: {
title: '豌豆荚',
prefix: '',
debug: true
}
},
files: [{
expand: true,
cwd: '<%= paths.app %>/pages/',
src: '**/*.dot.html',
dest: '<%= paths.tmp %>',
ext: '.html',
flatten: false
}]
},
staging: {
options: {
env: {
title: '豌豆荚',
prefix: '',
debug: false
}
},
files: [{
expand: true,
cwd: '<%= paths.app %>/pages/',
src: '**/*.dot.html',
dest: '<%= paths.tmp %>',
ext: '.html',
flatten: false
}]
},
dist: {
options: {
env: {
title: '豌豆荚',
prefix: 'http://www.wandoujia.com',
debug: false
}
},
files: [{
expand: true,
cwd: '<%= paths.app %>/pages/',
src: '**/*.dot.html',
dest: '<%= paths.tmp %>',
ext: '.html',
flatten: false
}]
}
},
cdn: {
options: {
cdn: 'http://s.wdjimg.com/www',
flatten: true
},
dist: {
src: ['<%= paths.dist %>/**/*.html', '<%= paths.dist %>/**/*.css'],
}
},
wandoulabs_deploy: {
options: grunt.file.readJSON('OathKeeper/frontend/ldap.json'),
product: {
deployCDN: {
src: '<%= paths.dist %>',
target: 'www'
}
}
}
});
grunt.registerTask('serve', [
'clean:server',
'concurrent:server',
'configureRewriteRules',
'connect:server',
'jade:server',
'stencil:server',
'open',
'watch'
]);
grunt.registerTask('server', function () {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve']);
});
grunt.registerTask('test', [
'jshint:test'
]);
grunt.registerTask('test:travis', [
'jshint:test'
]);
grunt.registerTask('build:staging', [
'clean:dist',
'concurrent:staging',
'stencil:staging',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'imagemin',
'copy:html',
'rev',
'usemin',
'htmlmin'
]);
grunt.registerTask('build:production', [
'clean:dist',
'concurrent:dist',
'stencil:dist',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'imagemin',
'copy:html',
'rev',
'usemin',
'cdn:dist',
'copy:statics',
'htmlmin',
'copy:oldStyles',
'copy:components',
'wandoulabs_deploy:product'
]);
};
{
"name": "package",
"version": "0.0.0",
"description": "Put your description for this project here.",
"repository": {
"type": "git",
"url": ""
},
"dependencies": {},
"devDependencies": {
"matchdep": "~0.1.2",
"grunt": "~0.4.1",
"grunt-rev": "~0.1.0",
"grunt-open": "~0.2.2",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-imagemin": "~0.1.4",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-compress": "~0.4.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-usemin": "~2.0.0",
"grunt-concurrent": "~0.3.1",
"grunt-contrib-connect": "~0.3.0",
"grunt-contrib-jshint": "~0.7.0",
"grunt-bump": "~0.0.11",
"connect-livereload": "~0.2.0",
"grunt-conventional-changelog": "~1.0.0",
"grunt-stencil": "~1.0.1",
"grunt-connect-rewrite": "~0.2.0",
"grunt-text-replace": "~0.3.7",
"grunt-wandoulabs-deploy": "git+ssh://[email protected]:wandoulabs/grunt-wandoulabs-deploy.git",
"time-grunt": "^0.3.1",
"grunt-cdn" : "0.5.2",
"grunt-jade": "^0.5.0"
},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "grunt test:travis --verbose;"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment