Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 231d6c3

Browse files
committed
optimization: put HTML templates into templates.js
1 parent 492184e commit 231d6c3

File tree

7 files changed

+55
-2
lines changed

7 files changed

+55
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.git*
2+
dist
23
!.gitkeep
34
node_modules/
45
!.bowerrc

gulpfile.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var gulp = require('gulp');
2+
var runSequence = require('run-sequence');
3+
var del = require('del');
4+
var templateCache = require('gulp-angular-templatecache');
5+
6+
gulp.task('clean', function (cb) {
7+
return del([
8+
'dist/**/*',
9+
], function (err, deletedFiles) {
10+
console.log('Files deleted:', deletedFiles.join(', '));
11+
cb(err, deletedFiles);
12+
});
13+
});
14+
15+
gulp.task('build:copy', function() {
16+
return gulp.src([
17+
'src/**/*',
18+
'!src/partials/**/*'
19+
])
20+
.pipe(gulp.dest('dist'));
21+
});
22+
23+
gulp.task('templates', ['build:copy'], function () {
24+
return gulp.src('src/partials/**/*.html')
25+
.pipe(templateCache('js/templates.js', {root: 'partials'}))
26+
.pipe(gulp.dest('dist'));
27+
});
28+
29+
gulp.task('build:all', ['templates', 'build:copy']);
30+
31+
gulp.task('build', function(cb) {
32+
console.log("Build started");
33+
runSequence(
34+
'clean',
35+
'build:all',
36+
cb);
37+
});
38+
39+
gulp.task('watch', function() {
40+
gulp.watch('src/**/*', ['build']);
41+
});
42+
43+
gulp.task('default', ['build']);

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
"private": true,
44
"devDependencies": {
55
"bower": "^1.3.1",
6+
"del": "^2.0.2",
67
"grunt": "~0.4.2",
7-
"grunt-bowercopy": "~1.0.0"
8+
"grunt-bowercopy": "~1.0.0",
9+
"gulp": "^3.9.0",
10+
"gulp-angular-templatecache": "^1.8.0",
11+
"run-sequence": "^1.1.4"
812
},
913
"scripts": {
1014
"postinstall": "grunt bowercopy",

scripts/build_dist.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
rm -rf dist
22
mkdir -p dist
33
npm install
4-
cp -rf src/* dist/
4+
gulp

src/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<script src="3rdparty/marked/marked.js"></script>
1616
<script src="js/alert.js"></script>
1717
<script src="js/app.js"></script>
18+
<script src="js/templates.js"></script>
1819
<script src="js/controllers.js"></script>
1920
<script src="js/directives.js"></script>
2021
<script src="js/filters.js"></script>

src/js/app.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var app = angular.module('app', [
88
'ui.bootstrap',
99
'ngSanitize',
1010
'ngRoute',
11+
'templates',
1112
'prControllers',
1213
'appFilters',
1314
'appDirectives',
@@ -41,3 +42,5 @@ var app = angular.module('app', [
4142
$rootScope.repoName = current.params.repoName;
4243
});
4344
});
45+
46+
angular.module("templates", []);

src/js/templates.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Placeholder for HTML templates

0 commit comments

Comments
 (0)