Skip to content

Commit 9fd160d

Browse files
committed
feat(gulp): Add inject tasks for css and js into index.html, add them to serve task
Tested to work with plain js, sass, other defaults... gulp serve works :]
1 parent 996919f commit 9fd160d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

app/templates/_package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"gulp-clean": "^0.3.1",
3838
"gulp-filter": "^2.0.2",
3939
"gulp-imagemin": "^2.2.1",
40+
"gulp-inject": "^1.3.1",
4041
"gulp-jshint": "^1.11.0",
4142
"gulp-karma": "0.0.4",
4243
"gulp-livereload": "^3.8.0",

app/templates/gulpfile.babel.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ let styles = lazypipe()
115115
// Tasks //
116116
///////////
117117

118+
gulp.task('inject', cb => {
119+
runSequence(['inject:js', 'inject:css'], cb);
120+
});
121+
122+
gulp.task('inject:js', () => {
123+
return gulp.src(paths.views.main)
124+
.pipe(plugins.inject(gulp.src(_.union(
125+
paths.client.scripts
126+
), {read: false}), {
127+
starttag: '<!-- injector:js -->',
128+
endtag: '<!-- endinjector -->',
129+
transform: (filepath) => '<script src="' + filepath.replace('/client/', '') + '"></script>'
130+
}))
131+
.pipe(gulp.dest('client'));
132+
});
133+
134+
gulp.task('inject:css', () => {
135+
return gulp.src(paths.views.main)
136+
.pipe(plugins.inject(gulp.src('/client/**/*.css', {read: false}), {
137+
starttag: '<!-- injector:css -->',
138+
endtag: '<!-- endinjector -->',
139+
transform: (filepath) => '<link rel="stylesheet" href="' + filepath.replace('/client/', '').replace('/.tmp/', '') + '">'
140+
}))
141+
.pipe(gulp.dest('client'));
142+
});
143+
118144
gulp.task('styles', styles);<% if(filters.coffee) { %>
119145

120146
gulp.task('coffee', () =>
@@ -171,6 +197,8 @@ gulp.task('watch', () => {
171197
gulp.task('serve', (callback) => {
172198
runSequence('clean:tmp',
173199
['lint:scripts'],
200+
'inject:js',
201+
'inject:css',
174202
'bower',
175203
['start:server', 'start:client'],
176204
'watch',

0 commit comments

Comments
 (0)