Skip to content

Commit

Permalink
use $templateCache for production
Browse files Browse the repository at this point in the history
* Makes sure when a new version of the JavaScript code is deployed
  the users will not need a hard refresh.

* It also avoids doing requests to the server for templates in production.

Signed-off-by: Javier Martin Montull <javier.martin.montull@cern.ch>
  • Loading branch information
jmartinm committed Jun 28, 2017
1 parent e238197 commit 47a090c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var path = require('path');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
var templateCache = require('gulp-angular-templatecache');

/**
* File patterns
Expand Down Expand Up @@ -73,26 +74,37 @@ var lintFiles = [
// run all the build tasks
gulp.task('build', ['clean.build'], function (done) {
runSequence(
'build.src', 'build.templates', done
'build.templates', 'build.src', done
);
});


// build the javascript files
gulp.task('build.src', function() {
gulp.src(sourceFiles)
gulp.task('build.src', function(done) {
gulp.src(sourceFiles.concat([path.join(rootDirectory, './dist/templates/templates.js')]))
.pipe(plugins.plumber())
.pipe(plugins.concat('inspirehep-search.js'))
.pipe(gulp.dest('./dist/'))
.pipe(plugins.uglify())
.pipe(plugins.rename('inspirehep-search.min.js'))
.pipe(plugins.header(licences.javascript))
.pipe(gulp.dest('./dist'));
.pipe(gulp.dest('./dist'))
.on('end', done);
});

// move the templates to dist
gulp.task('build.templates', function() {


// inline templates with $templateCache
gulp.task('build.templates', function(done) {
gulp.src(templates, {cwd: sourceDirectory + 'inspirehep-search-js'})
.pipe(gulp.dest('./dist/templates'));
.pipe(templateCache('templates.js', {
moduleSystem: 'IIFE',
standalone: true,
root: '/static/node_modules/inspirehep-search-js/dist/templates/',
module: 'inspirehepSearchTemplates'
}))
.pipe(gulp.dest('./dist/templates'))
.on('end', done);
});

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"coveralls": "^2.11.4",
"del": "^2.1.0",
"gulp": "^3.8.7",
"gulp-angular-templatecache": "^2.0.0",
"gulp-concat": "^2.3.4",
"gulp-coveralls": "^0.1.4",
"gulp-flatten": "^0.3.1",
Expand Down
1 change: 1 addition & 0 deletions src/inspirehep-search-js/inspirehepSearch.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'inspirehepExport',
'inspirehepPermissions',
'inspirehepSearch.filters',
'inspirehepSearchTemplates',
'ui.bootstrap',
'authors'
]);
Expand Down

0 comments on commit 47a090c

Please sign in to comment.