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
162
163
164
165
166
167
168
169
170
| // This is the main application configuration file. It is a Grunt
// configuration file, which you can learn more about here:
// https://github.com/cowboy/grunt/blob/master/docs/configuring.md
//
module.exports = function(grunt) {
grunt.initConfig({
// define the debug/release directories for distribution.
// TODO, maybe remove it later. I don't like hardcode, but sometimes
// hardcode is more simple.
dirs: {
debug: "dist/debug", // debug files under the folder
release: "dist/release" // release files under the folder
},
// The clean task ensures all files are removed from the dist/ directory so
// that no files linger from previous builds.
clean: ["<config:dirs.debug>", "<config:dirs.release>"],
// The lint task will run the build configuration and the application
// JavaScript through JSHint and report any errors. You can change the
// options for this task, by reading this:
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md
lint: {
beforeconcat: [
"app/**/*.js"
],
afterconcat: [
"dist/debug/assets/js/require/require.js"
]
},
// The jshint option for scripturl is set to lax, because the anchor
// override inside main.js needs to test for them so as to not accidentally
// route.
jshint: {
options: {
scripturl: true
}
},
// The copy task is to copy files from source to distribution directory.
copy: {
debug: {
src: ["assets/css/**/*.css", "favicon.ico"],
renames: {
"index.noconfig.html": "index.html"
},
dest: "<config:dirs.debug>"
},
release: {
src: ["favicon.ico"],
renames: {
"index.noconfig.html": "index.html"
},
dest: "<config:dirs.release>"
}
},
// The concatenate task is used here to merge the require.js into the
// application code. It's named dist/debug/assets/js/require/require.js,
//because we want to only load one script file in index.html.
concat: {
"dist/debug/assets/js/require/require.js": [
"assets/js/require/require.js",
"dist/debug/assets/js/require/require.js"
]
},
// This task uses the MinCSS Node.js project to take all your CSS files in
// order and concatenate them into a single CSS file named index.css. It
// also minifies all the CSS as well. This is named index.css, because we
// only want to load one stylesheet in index.html.
mincss: {
"dist/release/assets/css/index.css": [
"assets/css/application.css"
]
},
// Takes the built require.js file and minifies it for filesize benefits.
min: {
"dist/release/assets/js/require/require.js": [
"dist/debug/assets/js/require/require.js"
]
},
// Running the server without specifying an action will run the defaults,
// port: 8080 and host: 127.0.0.1. If you would like to change these
// defaults, simply add in the properties `port` and `host` respectively.
//
// Changing the defaults might look something like this:
//
// server: {
// host: "127.0.0.1", port: 9001
// debug: { ... can set host and port here too ...
// }
//
// To learn more about using the server task, please refer to the code
// until documentation has been written.
// Run below commands will cause:
// $ bbb server
// Run server under . folder. It uses require.js to load all needed
// js files, templates and css files.
// $ bbb server:debug
// Run server under dist/debug folder. All js files are merged into one
// require.js. Make sure you run 'bbb debug' firstly.
// $ bbb server:debug
// Run server under dist/release folder.
// All js files are merged into one require.js and minized. All css
// files are merged into one and minized.
// Make sure you run 'bbb release' firstly.
server: {
port: 8000,
base: ".",
folders: {
"app": "app",
"assets": "assets"
},
debug: {
folders: {
"app": "dist/debug",
"assets": "dist/debug/assets",
"": "dist/debug"
}
},
release: {
folders: {
"app": "dist/release",
"assets": "dist/release/assets",
"": "dist/release"
}
}
},
// This task uses James Burke's excellent r.js AMD build tool. In the
// future other builders may be contributed as drop-in alternatives.
requirejs: {
// Include the main configuration file
mainConfigFile: "app/config.js",
// Output file
out: "dist/debug/assets/js/require/require.js",
// Root application module
name: "config",
// Do not wrap everything in an IIFE
wrap: false
}
});
// load tasks from tasks/ folder.
grunt.loadTasks("tasks");
// The default task will remove all contents inside the dist/ folder, lint
// all your code.
grunt.registerTask("default", "clean lint:beforeconcat");
// The debug task will remove all contents inside the dist/ folder, lint all
// js code under app/ folder, copy files to dist/debug folder, combine all
// application files into require.js, and then concat real require.js with
// the application require.js file.
grunt.registerTask("debug", "default copy:debug requirejs concat");
// The release task will perform debug task, copy files to dist/release folder,
// minmize css file, and minimize require.js into dist/release.
grunt.registerTask("release", "debug copy:release mincss min");
};
|