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

Commit 1fbb27c

Browse files
committed
fix(grunt:cdnify): preserve cdnified scripts in build
Previously, the script references in index.html that were changed by the cdnify step would later be overwritten by the usemin task. Now, cdnify runs before useminPrepare and the usemin task is configured to include references for cdnified scripts right before the actual block replacements.
1 parent cb9d420 commit 1fbb27c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

templates/common/root/_Gruntfile.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ module.exports = function (grunt) {
363363
// concat, minify and revision files. Creates configurations in memory so
364364
// additional tasks can operate on them
365365
useminPrepare: {
366-
html: '<%%= yeoman.app %>/index.html',
366+
html: '<%%= yeoman.dist %>/index.html',
367367
options: {
368368
dest: '<%%= yeoman.dist %>',
369369
flow: {
@@ -391,6 +391,17 @@ module.exports = function (grunt) {
391391
],
392392
patterns: {
393393
js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']]
394+
},
395+
blockReplacements: {
396+
// Include cdnified scripts followed by usemin dest script
397+
js: function (block) {
398+
var scripts = block.src.filter(function (src) {
399+
return src.startsWith('//');
400+
}).concat(block.dest);
401+
return scripts.map(function (src) {
402+
return '<script src="' + src + '"></script>';
403+
}).join('\n');
404+
}
394405
}
395406
}
396407
},
@@ -495,6 +506,14 @@ module.exports = function (grunt) {
495506

496507
// Copies remaining files to places other tasks can use
497508
copy: {
509+
html: {
510+
files: [{
511+
expand: true,
512+
cwd: '<%= yeoman.app %>',
513+
src: '*.html',
514+
dest: '<%= yeoman.dist %>',
515+
}],
516+
},
498517
dist: {
499518
files: [{
500519
expand: true,
@@ -503,7 +522,6 @@ module.exports = function (grunt) {
503522
dest: '<%%= yeoman.dist %>',
504523
src: [
505524
'*.{ico,png,txt}',
506-
'*.html',
507525
'images/{,*/}*.{webp}',
508526
'styles/fonts/{,*/}*.*'
509527
]
@@ -606,14 +624,15 @@ module.exports = function (grunt) {
606624
'clean:dist',
607625
'wiredep',<% if (typescript) { %>
608626
'tsd:refresh',<% } %>
627+
'copy:html',
628+
'cdnify',
609629
'useminPrepare',
610630
'concurrent:dist',
611631
'postcss',
612632
'ngtemplates',
613633
'concat',
614634
'ngAnnotate',
615635
'copy:dist',
616-
'cdnify',
617636
'cssmin',
618637
'uglify',
619638
'filerev',

0 commit comments

Comments
 (0)