发布于 2016-01-05 12:07:31 | 404 次阅读 | 评论: 0 | 来源: PHPERZ
Grunt JavaScript构建工具
Grunt 是一个基于任务的JavaScript工程命令行构建工具
'use strict';
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: {
src: 'src',
dist: 'dist'
},
watch: {
assemble: {
files: ['<%= config.src %>/{content,data,templates}/{,*/}*.{md,hbs,yml,html}','<%= config.src %>/{assets}/{,*/}*.{less,css}','<%= config.src %>/{assets}/images/*', '<%= config.src %>/{assets}/**'],
tasks: ['assemble']
},
less: {
files: '<%= config.src %>/assets/{,*/}*.less',
tasks: ['less'],
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= config.dist %>/{,*/}*.html',
'<%= config.dist %>/assets/{,*/}*.less',
'<%= config.dist %>/assets/{,*/}*.css',
'<%= config.dist %>/assets/{,*/}*.js',
'<%= config.dist %>/assets/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
connect: {
options: {
port: 9000,
livereload: 35730,
// change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
livereload: {
options: {
open: true,
base: [
'<%= config.dist %>'
]
}
}
},
assemble: {
login: {
options: {
flatten: true,
assets: '<%= config.dist %>/assets',
layout: '<%= config.src %>/templates/layouts/login.hbs',
data: '<%= config.src %>/data/*.{json,yml}',
partials: '<%= config.src %>/templates/partials/*.hbs',
//plugins: ['assemble-contrib-permalinks','assemble-contrib-sitemap']
},
files: {
'<%= config.dist %>/': ['<%= config.src %>/templates/login/*.hbs']
}
},
pages: {
options: {
flatten: true,
assets: '<%= config.dist %>/assets',
layout: '<%= config.src %>/templates/layouts/default.hbs',
data: '<%= config.src %>/data/*.{json,yml}',
partials: '<%= config.src %>/templates/partials/*.hbs',
//plugins: ['assemble-contrib-permalinks','assemble-contrib-sitemap']
},
files: {
'<%= config.dist %>/': ['<%= config.src %>/templates/pages/*.hbs']
}
}
},
copy: {
theme: {
expand: true,
cwd: 'src/assets/',
src: '**',
dest: '<%= config.dist %>/assets/'
}
},
concat: {
options: {
separator: ';',
stripBanners: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +"xiajingsi" +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
basic: {
/*expand:true,
cwd: '<%= config.src %>/assets/js',*/
src: ["<%= config.src %>/assets/js/*.js","!<%= config.src %>/assets/js/custom.js","!<%= config.src %>/assets/js/jquery-ui-1.9.2.min.js","!<%= config.src %>/assets/js/zhifang.js"],
dest: '<%= config.dist %>/assets/js/plugin.js'
},
extras: {
/*expand:true,
cwd: '<%= config.src %>/assets/js',*/
src: ["<%= config.src %>/assets/js/custom.js","<%= config.src %>/assets/js/zhifang.js"],
dest: '<%= config.dist %>/assets/js/s-zhifang.js'
}
},
postcss: {
options: {
map: true,
processors: [
require('autoprefixer')()
]
},
dist: {
expand: true,
flatten: true,
cwd: '<%= config.dist %>/assets/css/',
src: 'zhifang.css',
dest: '<%= config.dist %>/assets/css/',
ext: '.css'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */'
},
my_target: {
files: [
{
expand: true,
cwd: '<%= config.dist %>/assets/js/',
src: 'plugin.js',
dest: '<%= config.dist %>/assets/js/',
ext: '.min.js', // Dest filepaths will have this extension.
}]
}
},
cssmin: {
options: {
beautify: {
ascii_only: true
}
},
my_target: {
files: [
{
expand: true,
cwd: '<%= config.src %>/assets/css/',
src: '*.css',
dest: '<%= config.dist %>/assets/css'
}
]
}
},
less: {
development: {
cleancss: true,
expand: true,
flatten: true,
cwd: '<%= config.src %>/assets/css/',
src: ['*.less'],
dest: '<%= config.dist %>/assets/css/',
ext: '.css'
},
},
// Before generating any new files,
// remove any previously-created files.
clean: ['<%= config.dist %>/**/*.{html,xml,less,js}']
});
grunt.loadNpmTasks('assemble');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('assemble-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('server', [
'build',
'connect:livereload',
'less:development',
'postcss',
'watch'
]);
grunt.registerTask('build', [
'clean',
'copy',
'assemble'
]);
grunt.registerTask('default', [
'build',
'less'
]);
grunt.registerTask('optimize', [
'uglify',
'cssmin',
'concat'
]);
grunt.registerTask('test', [
'build',
'connect:livereload',
'concat',
'uglify',
'less',
'watch'
]);
};