-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
84 lines (76 loc) · 1.94 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
module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-es6-module-transpiler");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.initConfig({
transpile: {
amd: {
type: 'amd',
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.js','!**/*.spec.js'],
dest: 'tmp/',
ext: '.amd.js'
},{
expand: true,
cwd: 'vendor/',
src: ['**/*.js','!**/*.spec.js', '!loader.js'],
dest: 'tmp/',
ext: '.amd.js'
}]
},
commonjs: {
type: 'cjs',
files: [{
expand: true,
cwd: 'lib/',
src: ['my_library/*.js'],
dest: 'dist/commonjs/',
ext: '.js'
},
{
src: ['lib/my_library.js'],
dest: 'dist/commonjs/main.js'
}]
}
},
concat: {
amd: {
src: "tmp/**/*.amd.js",
dest: "dist/CoObject.amd.js"
},
},
clean: {
tmp: ['tmp/'],
dist: ['dist']
},
browser: {
dist: {
src: ["vendor/loader.js", "dist/CoObject.amd.js"],
dest: "dist/Co.js",
options: {
barename: "co",
namespace: "Co"
}
}
}
});
grunt.registerMultiTask('browser', "Export a module to the window", function() {
var opts = this.options();
this.files.forEach(function(f) {
var output = ["(function(globals) {"];
output.push.apply(output, f.src.map(grunt.file.read));
output.push(grunt.template.process(
'window.<%= namespace %> = requireModule("<%= barename %>");', {
data: {
namespace: opts.namespace,
barename: opts.barename
}
}));
output.push('})(window);');
grunt.file.write(f.dest, grunt.template.process(output.join("\n")));
});
});
grunt.registerTask("build", ["clean:tmp", "transpile", "concat:amd", "browser"]);
}