-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
119 lines (115 loc) · 3.46 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module.exports = function(grunt) {
var config = {
app: 'app',
dist: 'dist'
};
grunt.initConfig({
config: config,
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
options:{
report: "min",//输出压缩率,可选的值有 false(不输出信息),gzip
mangle: true //混淆
},
files: {
'<%= config.dist %>/scripts/index.build.js': ['<%= config.app %>/scripts/index.build.js'],
'<%= config.dist %>/scripts/head.build.js': ['<%= config.app %>/scripts/head.build.js']
}
}
},
imagemin: { // Task
dynamic: { // Another target
options: { // Target options
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }],
//use: [mozjpeg()]
},
files: [{
expand: true, // Enable dynamic expansion
cwd: 'dist/images', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif,svg}'], // Actual patterns to match
dest: 'dist/images' // Destination path prefix
}]
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
/*
files: { // Dictionary of files
'build/index.html': 'index.html',
'build/static/views/*.html': '.tmp/static/views/*.html',
{expand: true, cwd: 'dist/html', src: ['*.html'], dest: 'dist/html'}
}
*/
files: [{
expand: true,
cwd: '<%= config.dist %>',
src: '**/*.html',
dest: '<%= config.dist %>'
}]
}
},
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: [{
expand: true,
cwd: '<%= config.dist %>/styles',
src: ['cssreset-min.css', 'index.css'],
dest: '<%= config.dist %>/styles'
}]
}
},
'font-spider': {
options: {},
main: {
src: './dist/**/*.html'
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
dest: '<%= config.dist %>',
src: [
'*.{ico,png,txt}',
'images/{,*/}*.*',
//'scripts/{,*/}*.js',
// 'styles/index.css',
'{,*/}*.html',
'styles/fonts/{,*/}*.*'
]
}]
}
},
clean: {
build: {
src: "dist"
}
}
});
// 加载包含任务的插件。
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-font-spider');
grunt.loadNpmTasks('grunt-contrib-clean');
// 默认被执行的任务列表。
grunt.registerTask('default', ['clean', 'copy', 'uglify', 'htmlmin', /*'cssmin',*/ 'imagemin', 'font-spider']);
};