Skip to content

Commit c9bb981

Browse files
committed
take the *html fragment* out of the js file, and use *grunt-angular-templates* and *grunt-replace* plugin to generate the templateCache and insert it into the js file
1 parent 2a8ffc1 commit c9bb981

File tree

9 files changed

+1399
-20
lines changed

9 files changed

+1399
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.idea/
33
bower_components/
4+
temp/

Gruntfile.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,63 @@ module.exports = function (grunt)
3737
rzslider: {
3838
files: {
3939
'dist/rzslider.min.js': [
40-
'src/rzslider.js'
40+
'dist/rzslider.js'
4141
]
4242
}
4343
}
44+
},
45+
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([\'$templateCache\', function($templateCache) {\n' + script + '\n}]);';
67+
}
68+
}
69+
}
70+
},
71+
72+
replace: {
73+
dist: {
74+
options: {
75+
patterns: [
76+
{
77+
match: /\/\*templateReplacement\*\//,
78+
replacement: '<%= grunt.file.read("temp/templates.js") %>'
79+
}
80+
]
81+
},
82+
files: [
83+
{expand: true, flatten: true, src: ['src/rzslider.js'], dest: 'dist/'}
84+
]
85+
}
4486
}
87+
4588
});
4689

4790
grunt.loadNpmTasks('grunt-contrib-uglify');
4891
grunt.loadNpmTasks('grunt-recess');
92+
grunt.loadNpmTasks('grunt-angular-templates');
93+
grunt.loadNpmTasks('grunt-replace');
4994

5095
grunt.registerTask('default', ['css', 'js']);
5196

5297
grunt.registerTask('css', ['recess']);
53-
grunt.registerTask('js', ['uglify']);
98+
grunt.registerTask('js', ['ngtemplates','replace', 'uglify']);
5499
};

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ <h2>Toggle slider example</h2>
115115
</body>
116116

117117
<script src="../bower_components/angular/angular.min.js"></script>
118-
<script src="../src/rzslider.js"></script>
118+
<script src="../dist/rzslider.js"></script>
119119
<script>
120120
var app = angular.module('plunker', ['rzModule']);
121121

0 commit comments

Comments
 (0)