-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
115 lines (105 loc) · 2.58 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
'use strict';
// Transparently allow require-ing `component.jsx`.
require('node-jsx').install({ extension: '.jsx' });
var fs = require('fs');
var path = require('path');
var littlest = require('littlest-isomorph');
var vm = require('vm');
var dependencies = [
'littlest-isomorph',
'proxy-client',
'react',
'when'
];
module.exports = function (grunt) {
var server;
grunt.initConfig({
browserify: {
dependencies: {
src: [],
dest: 'public/dependencies.bundle.js',
options: {
require: dependencies
}
},
app: {
src: ['bin/client'],
dest: 'public/app.bundle.js',
options: {
external: dependencies,
transform: ['envify', 'reactify']
}
}
},
less: {
client: {
src: ['styles/bundle.less'],
dest: 'public/bundle.css',
options: {
paths: function (srcFile) {
return [
path.dirname(srcFile),
path.resolve(__dirname, 'node_modules')
];
},
relativeUrls: true
}
}
},
watch: {
client: {
files: ['bin/client'],
tasks: ['browserify:app'],
options: {
atBegin: true
}
},
shared: {
files: ['lib/**/*.js', 'lib/**/*.jsx', 'lib/**/*.json'],
tasks: ['browserify:app', 'grunt:index']
},
dependencies: {
files: ['package.json'],
tasks: ['browserify:dependencies']
},
index: {
files: ['_index.html'],
tasks: ['grunt:index']
},
styles: {
files: ['styles/**/*.less'],
tasks: ['less'],
options: {
atBegin: true
}
},
options: {
spawn: false
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('grunt', function (command) {
grunt.util.spawn({
cmd: 'grunt',
args: [command],
opts: {
stdio: 'inherit'
}
}, this.async());
});
grunt.registerTask('index', function () {
var context = require('./lib/context');
var renderer = littlest.StaticRenderer.createRenderer({
templatePath: path.resolve(__dirname, '_index.html')
});
fs.writeFileSync(
path.resolve(__dirname, 'index.html'),
renderer.render(context.router.getRoute('/'), context)
);
});
grunt.registerTask('default', ['browserify', 'less', 'index']);
grunt.registerTask('dev', ['browserify:dependencies', 'index', 'watch']);
};