Skip to content

Commit 2ad1f0e

Browse files
author
Valentin Hervieu
committed
Add a watch and serve task to grunt
1 parent b7a01c5 commit 2ad1f0e

File tree

2 files changed

+122
-98
lines changed

2 files changed

+122
-98
lines changed

Gruntfile.js

Lines changed: 120 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,137 @@
1-
module.exports = function (grunt)
2-
{
3-
// Project configuration.
4-
grunt.initConfig({
1+
module.exports = function(grunt) {
2+
// Project configuration.
3+
grunt.initConfig({
54

6-
pkg: grunt.file.readJSON('package.json'),
5+
pkg: grunt.file.readJSON('package.json'),
76

8-
minBanner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
9-
'(c) <%= pkg.author %>, <%= pkg.repository.url %> - ' +
10-
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
7+
minBanner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
8+
'(c) <%= pkg.author %>, <%= pkg.repository.url %> - ' +
9+
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
1110

12-
recess: {
13-
options: {
14-
compile: true
15-
},
11+
recess: {
12+
options: {
13+
compile: true
14+
},
1615

17-
slider: {
18-
src: ['src/rzslider.less'],
19-
dest: 'dist/rzslider.css'
20-
},
16+
slider: {
17+
src: ['src/rzslider.less'],
18+
dest: 'dist/rzslider.css'
19+
},
2120

22-
min: {
23-
options: {
24-
compress: true,
25-
banner: '<%= minBanner %>'
21+
min: {
22+
options: {
23+
compress: true,
24+
banner: '<%= minBanner %>'
25+
},
26+
src: ['dist/rzslider.css'],
27+
dest: 'dist/rzslider.min.css'
28+
}
2629
},
27-
src: ['dist/rzslider.css'],
28-
dest: 'dist/rzslider.min.css'
29-
}
30-
},
3130

32-
uglify: {
33-
options: {
34-
report: 'min',
35-
banner: '<%= minBanner %>'
36-
},
37-
rzslider: {
38-
files: {
39-
'dist/rzslider.min.js': [
40-
'dist/rzslider.js'
41-
]
42-
}
43-
}
44-
},
31+
uglify: {
32+
options: {
33+
report: 'min',
34+
banner: '<%= minBanner %>'
35+
},
36+
rzslider: {
37+
files: {
38+
'dist/rzslider.min.js': [
39+
'dist/rzslider.js'
40+
]
41+
}
42+
}
43+
},
4544

46-
ngtemplates: {
47-
app: {
48-
src: 'src/**.html',
49-
dest: 'temp/templates.js',
50-
options: {
51-
htmlmin: {
52-
collapseBooleanAttributes: true,
53-
collapseWhitespace: true,
54-
removeAttributeQuotes: true,
55-
removeComments: true, // Only if you don't use comment directives!
56-
removeEmptyAttributes: true,
57-
removeRedundantAttributes: true,
58-
removeScriptTypeAttributes: true,
59-
removeStyleLinkTypeAttributes: true
60-
},
61-
module: 'rzModule',
62-
url: function(url) {
63-
return url.replace('src/', '');
64-
},
65-
bootstrap: function (module, script) {
66-
return 'module.run(function($templateCache) {\n' + script + '\n});';
67-
}
68-
}
69-
}
70-
},
45+
ngtemplates: {
46+
app: {
47+
src: 'src/**.html',
48+
dest: 'temp/templates.js',
49+
options: {
50+
htmlmin: {
51+
collapseBooleanAttributes: true,
52+
collapseWhitespace: true,
53+
removeAttributeQuotes: true,
54+
removeComments: true, // Only if you don't use comment directives!
55+
removeEmptyAttributes: true,
56+
removeRedundantAttributes: true,
57+
removeScriptTypeAttributes: true,
58+
removeStyleLinkTypeAttributes: true
59+
},
60+
module: 'rzModule',
61+
url: function(url) {
62+
return url.replace('src/', '');
63+
},
64+
bootstrap: function(module, script) {
65+
return 'module.run(function($templateCache) {\n' + script + '\n});';
66+
}
67+
}
68+
}
69+
},
7170

72-
replace: {
73-
dist: {
74-
options: {
75-
patterns: [
76-
{
77-
match: /\/\*templateReplacement\*\//,
78-
replacement: '<%= grunt.file.read("temp/templates.js") %>'
71+
replace: {
72+
dist: {
73+
options: {
74+
patterns: [
75+
{
76+
match: /\/\*templateReplacement\*\//,
77+
replacement: '<%= grunt.file.read("temp/templates.js") %>'
78+
}
79+
]
80+
},
81+
files: [
82+
{expand: true, flatten: true, src: ['src/rzslider.js'], dest: 'dist/'}
83+
]
7984
}
80-
]
8185
},
82-
files: [
83-
{expand: true, flatten: true, src: ['src/rzslider.js'], dest: 'dist/'}
84-
]
85-
}
86-
},
8786

88-
ngAnnotate: {
89-
options: {
90-
singleQuotes: true,
91-
},
92-
rzslider: {
93-
files: [{
94-
'dist/rzslider.js': 'dist/rzslider.js'
95-
}, {
96-
expand: true,
97-
src: ['dist/rzslider.js']
98-
}
99-
]
100-
}
101-
}
87+
ngAnnotate: {
88+
options: {
89+
singleQuotes: true,
90+
},
91+
rzslider: {
92+
files: [{
93+
'dist/rzslider.js': 'dist/rzslider.js'
94+
}, {
95+
expand: true,
96+
src: ['dist/rzslider.js']
97+
}
98+
]
99+
}
100+
},
101+
watch: {
102+
all: {
103+
files: ['dist/*'],
104+
options: {
105+
livereload: true
106+
}
107+
},
108+
js: {
109+
files: ['src/*js', 'src/*.html'],
110+
tasks: ['js']
111+
},
112+
less: {
113+
files: ['src/*.less'],
114+
tasks: ['css']
115+
}
116+
},
117+
serve: {
118+
options: {
119+
port: 9000
120+
}
121+
}
102122

103-
});
123+
});
104124

105-
grunt.loadNpmTasks('grunt-contrib-uglify');
106-
grunt.loadNpmTasks('grunt-recess');
107-
grunt.loadNpmTasks('grunt-angular-templates');
108-
grunt.loadNpmTasks('grunt-replace');
109-
grunt.loadNpmTasks('grunt-ng-annotate');
125+
grunt.loadNpmTasks('grunt-contrib-uglify');
126+
grunt.loadNpmTasks('grunt-recess');
127+
grunt.loadNpmTasks('grunt-angular-templates');
128+
grunt.loadNpmTasks('grunt-replace');
129+
grunt.loadNpmTasks('grunt-ng-annotate');
130+
grunt.loadNpmTasks('grunt-contrib-watch');
131+
grunt.loadNpmTasks('grunt-serve');
110132

111-
grunt.registerTask('default', ['css', 'js']);
133+
grunt.registerTask('default', ['css', 'js']);
112134

113-
grunt.registerTask('css', ['recess']);
114-
grunt.registerTask('js', ['ngtemplates','replace', 'ngAnnotate', 'uglify']);
135+
grunt.registerTask('css', ['recess']);
136+
grunt.registerTask('js', ['ngtemplates', 'replace', 'ngAnnotate', 'uglify']);
115137
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"grunt-ng-annotate": "^1.0.1",
2020
"grunt-recess": "~0.4.0",
2121
"grunt-replace": "^0.11.0",
22+
"grunt-contrib-watch": "^0.6.1",
23+
"grunt-serve": "^0.1.6",
2224
"recess": "~1.1.9"
2325
},
2426
"author": "Rafal Zajac <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]>",

0 commit comments

Comments
 (0)