klei/gulp-inject

A way to use transform while spitting out correct script/link tags?

george-norris-salesforce opened this issue · 2 comments

Is there a way to use transform (to modify a path) while at the same time using injects detecting of file type and spitting out correct and/or <script>?

inject(
    gulp.src([
      `${config.jsDestfolder}/bundle.js`,
      `${config.cssDestfolder}/all.css`,
    ]),
    { transform: filePath => (
       //spits out correct path
       //but no html <link> or <script> tag
      `${process.env.HEROKU_PREFIX}${filePath}`
    )}
  )

I would like to know this too. I want to add a query parameter with a unique checkout hash to prevent caching.

Actually, google answered me : http://stackoverflow.com/questions/32077264/how-to-change-path-when-including-file-with-gulp-inject

       .pipe( $.inject(
        gulp.src( ['src/main/webapp/static/dist/**/*.js'], { read : false } ), {
            addRootSlash : false,
            //ignorePath : 'src/main/webapp',
            transform : function ( filePath, file, i, length ) {
                var newPath = filePath.replace( 'src/main/webapp/', '' );
                console.log('inject script = '+ newPath);
                return '<script src="${pageContext.request.contextPath}/' + newPath  + '"></script>';
            }
        } ))