-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
161 lines (139 loc) · 3.44 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
'use strict';
module.exports = function (grunt) {
grunt.registerTask('default', [
'less:dist',
'copy',
'concat',
'uglify',
]);
var jsFiles = grunt.file.read('index.html', 'utf-8')
.match(/<script src="[^"]+" defer>/g)
.map(function (x) {
return x.replace(/^<script src="|" defer>$/g, '');
});
// Set common initConfig.
var initConfig = {
pkg: grunt.file.readJSON('package.json'),
less: {
dev: {
files: {
'css/main.css': 'css/main.less',
},
},
dist: {
options: {
cleancss: true,
modifyVars: {
'image-base-url': 'images',
},
plugins: [
(function () {
var CleanCss = require('less-plugin-clean-css');
return new CleanCss({advanced: true});
}()),
],
},
files: {
'dist/app.min.css': 'css/main.less',
},
},
},
copy: {
simple: {
files: [{
expand: true,
src: [
'images/*',
'favicon.ico',
'*.php',
'.htaccess'
],
dest: 'dist/'
}],
},
logs: {
files: {
'dist/logs/human_access.log': 'logs/human_access.log.example',
'dist/logs/interested_access.log': 'logs/interested_access.log.example',
'dist/logs/use_access.log': 'logs/use_access.log.example',
},
},
html: {
files: {
'dist/': 'index.html',
},
options: {
process: function (src, filepath) {
src = src
// Replace scripts with a single script.
.replace(/(<script[^>]+><\/script>\s*)+/, '<script src="app.min.js" defer></script>\n')
// Inline styles.
.replace(
/<link rel="stylesheet"[^>]+>/,
'<style>'+
grunt.file.read('dist/app.min.css') +
'</style>')
// Remove indentation, and collapse multiple newlines into one.
.replace(/(^|\n)[\n\t]+/g, '$1')
// Remove comments.
.replace(/<!\-\-([\s\S]*?)\-\->/g, function (match, p1) {
if (p1[0] === '[') // Conditional comment.
return match;
else
return '';
});
return src;
},
}
},
},
concat: {
js: {
files: {
'dist/app.js': jsFiles,
},
options: {
// The content of the banner and the footer. Everything before 'MAIN;'
// is the banner, everything after it is the footer.
surround: (function () {
/* Base Convert <%= pkg.version %> (built <%= grunt.template.today("yyyy-mm-dd") %>) | (c) 2014 Dan Wolff | License: <%= pkg.licenses[0].type %> | baseconvert.com */
(function (window, undefined) {
MAIN;
// Disable debug.
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
}(this));
} + '').replace(/^.+?\{\s*|\}$|\t/g, '').split('MAIN;'),
banner: '<%= concat.js.options.surround[0] %>',
footer: '<%= concat.js.options.surround[1] %>',
},
},
},
uglify: {
options: {
preserveComments: function (node, comment) {
return /^!|License:|\/LICENCE/i.test(comment.value);
},
},
app: {
files: {
'dist/app.min.js': ['dist/app.js'],
}
},
},
watch: {
less: {
files: ['css/*.less', 'Gruntfile.js'],
tasks: ['less:dev'],
},
},
};
grunt.initConfig(initConfig);
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
};