javascript - Why does gulp-useref does not seem to work with a comment in the replacement section? -
i trying build gulp pipeline – want inject css index.html (this works fine) , grab other links source index.html , replace them in outputted version.
i noticed useref call mangling output if templated section replace includes html comment (see example below line comment). it’s easiest demonstrate code:
index.html (source file)
<!-- build:css styles/app.css--> <!--comment--> <link rel="stylesheet" href="/.tmp/styles.css"> <!-- endbuild --> gulpfile.js task
gulp.task('optimizereplace', function () { var assets = $.useref.assets({ searchpath: './' }); return gulp .src('./src/client/index.html') .pipe(assets) .pipe(assets.restore()) .pipe($.useref()) //this problem line; if inject not run first mangled .pipe(gulp.dest('./wwwroot/')); }); output (index.html)
</style> <link rel="stylesheet" href="styles/lib.css"> <link rel="stylesheet" href="styles/app.css-->" <!--comment> </head> <body> <div> the problem easier see in html, comment html comment looses end half of tag, after thinks comment.
the reason want put comment inside replacement section comment gulp-inject statement injects other references before useref. simplified down simple html comment causing problem.
this line causes problem: .pipe($.useref())
fyi following john papa’s course on pluralsight uses exact mechanism inject css , replace them – (the inject:css html comment delimiters mangled after useref):
<!-- build:css styles/app.css--> <!-- inject:css --> <link rel="stylesheet" href="/.tmp/styles.css"> <!-- endinject --> <!-- endbuild --> how can useref() replace template correct links but leave html comment intact?
thanks.
the reason version change check documentation https://www.npmjs.com/package/gulp-useref here have example:
gulp.task('optimize', ['templatecache', 'images'], function(){ var templatecache = config.temp + config.templatecache.files; return gulp .src(config.index) .pipe($.plumber()) .pipe($.inject(gulp.src(templatecache, {read: false}, {starttag: ''}))) .pipe($.useref({ searchpath: './' })) .pipe(gulp.dest(config.build)); }); hope helps
Comments
Post a Comment