-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGruntfile.js
103 lines (96 loc) · 3.11 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
var localConfig = {
product: 'touchjs', //项目名,用于md5后的资源 如<%- staticBase %>/xx/a.js替换成<%- staticBase %>/xx/a.131.js
srcDir: '', //源文件的目录, 编译文件 的来源 grunt.option('p')
releaseDir: 'dist/'
};
module.exports = function(grunt) {
'use strict';
// require('time-grunt')(grunt);
var path = require('path');
var config = localConfig;
//如果没有服务器配置,采用本地配置
if(!config.product) {
var localConfigFile = grunt.file.read('./config/localConfig.js');
eval(localConfigFile); //会localConfig值
for(var key in localConfig) {
config[key] = localConfig[key];
}
}
grunt.initConfig({
product : config.product,
clean: {
folders: [config.releaseDir]
},
copy: {
main: {
files: [{
expand: true,
cwd: path.join(config.srcDir, 'src'),
src: ['**/*'],
// filter: changeFilter,
dest: config.releaseDir
}]
}
},
concat: {
main: {
files: [{
expand: true,
cwd: path.join(config.srcDir, 'src'),
src: ['**/*.js'],
// filter: changeFilter,
dest: config.releaseDir
}]
}
},
uglify: {
options: {
banner: '/*! js <%= product %> <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %> */\n'
},
min: {
expand: true,
cwd: config.releaseDir,
src: '**/*.js',
dest: config.releaseDir
}
},
babel: {
options: {
sourceMap: true,
presets: ['babel-preset-es2015']
},
dist: {
files: {
'dist/touch.js': 'dist/touch.js'
}
},
test: {
files: {
'dist/touch.js': 'dist/touch.js'
}
}
},
eslint: {
target: ['./src/**/*.js']
},
watch: {
options: {
livereload: true
},
local: {
files: [path.join(config.srcDir, 'src') + '/**'],
tasks: ['eslint', 'clean', 'copy:main', 'concat','babel:dist','uglify' ]
}
}
});
grunt.registerTask('local', ['eslint', 'clean', 'copy:main', 'concat', 'watch:local']);
grunt.registerTask('default', ['clean', 'copy:main', 'concat', 'babel:dist','uglify']);
grunt.registerTask('test', ['babel:test','uglify']);
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-babel');
};