-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
120 lines (114 loc) · 3.69 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
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
ts: {
dist: {
src: ['src/main/ts/**/*.ts', 'src/main/d.ts/**/*.d.ts'],
out: 'build/out.js',
options: {
module: 'amd', //or commonjs
target: 'es5', //or es3
basePath: 'src/main/ts',
sourceMap: true,
declaration: false,
comments: true
}
}
},
clean: {
all: ["build", "dist", "dist.zip", "js13k.zip"],
dist: ["dist"]
},
'closure-compiler': {
js1k: {
closurePath: 'libbuild/closure-compiler',
js: 'build/out.js',
jsOutputFile: 'dist/out.min.js',
maxBuffer: 500,
reportFile: 'closure.txt',
options: {
compilation_level: 'ADVANCED_OPTIMIZATIONS',
language_in: 'ECMASCRIPT5',
// ES6 output is not supported!!
language_out: 'ECMASCRIPT5',
externs: 'src/main/externs/js1k.js'
}
}
},
inline: {
dist: {
src: 'dist/index.html',
dest: 'dist/index.html'
}
},
replace: {
js1k: {
src: ['dist/out.min.js'],
overwrite: true,
replacements: [{
from: /(=|:|return |\(|,)function\(([^\)]*)\)/g,
to:"$1($2)=>"
}, {
from: /var [^;=]*;/g,
to: ""
}, {
from: /var /g,
to: ""
}, {
from: /(\n|\r)/g,
to: ""
}/*, {
from: /=(\w+\|0);/g,
to: "=($1);"
}*//*, {
// note, this is a symptom that TS is initalizing your local vars (which you don't want)
from: /void 0/g,
to: "0"
}*/]
},
shim: {
src: ['dist/index.html'],
overwrite: true,
replacements: [{
from: /<!--demo--><script>/g,
to:"<script type='demo'>"
}]
}
},
inline: {
js1k: {
src: 'shim.html',
dest: 'dist/index.html'
}
},
devUpdate: {
main: {
options: {
//task options go here
updateType: 'force',
reportUpdated: true
}
}
}
});
// clean
grunt.loadNpmTasks('grunt-contrib-clean');
// load the plugin that provides the closure compiler
grunt.loadNpmTasks('grunt-closure-compiler');
// Load the plugin that provides the "TS" task.
grunt.loadNpmTasks('grunt-ts');
// copy
grunt.loadNpmTasks('grunt-contrib-copy');
// replace text in file
grunt.loadNpmTasks('grunt-text-replace');
// update version
grunt.loadNpmTasks('grunt-dev-update');
// inline js
grunt.loadNpmTasks('grunt-inline');
// Default task(s).
grunt.registerTask('reset', ['clean:all']);
grunt.registerTask('prod', ['ts:dist']);
grunt.registerTask('js1k', ['prod', 'closure-compiler:js1k', 'replace:js1k', 'inline:js1k', 'replace:shim']);
grunt.registerTask('default', ['js1k']);
};