Gruntfile.js
1.6 KB
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
'use strict';
var glob = require('glob');
var fs = require('fs');
module.exports = function(grunt) {
grunt.initConfig({
concat: {
dist: {
src: [
'utils.js',
'upload.js',
'template.js',
'emoji.js',
'cs.js'
],
dest: 'temp/cs.js'
}
},
uglify: {
dist: {
src: [
'temp/cs.js',
'temp/template.js'
],
dest: 'dist/cs.min.js'
}
},
cssmin: {
dist: {
src: 'cs.css',
dest: 'dist/cs.min.css'
}
},
clean: {
dist: {
src: 'temp'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('html-to-js',function () {
var template = {};
glob.sync('./templates/**/*.html').forEach(filePath => {
var content = fs.readFileSync(filePath, {
encoding: 'utf8'
});
var key = filePath.replace(/^\.\//, '');
template[key] = content;
});
var dest = './temp/template.js';
var outputContent = 'RCS.templateCache=' + JSON.stringify(template, null, 4) + ';';
fs.writeFileSync(dest, outputContent);
});
grunt.registerTask('dist', ['concat', 'html-to-js', 'uglify', 'cssmin', 'clean']);
}