Droid Kree
Droid Kree

Reputation: 161

Gulp inject css & javascript into jsp file not working

During Gulp build .tmp process all js & css files are injected into temporary jsp file, but when dist process starts combined js & css files are generated but not injected into dist jsp file.

For same case build with html, file gulp working fine.

Is it possible to use gulp-inject for JSP files to inject javascript & css files into it? And how?

Upvotes: 0

Views: 684

Answers (2)

davidwillianx
davidwillianx

Reputation: 401

I guess you don't need any hack to solve this problem:

gulp.task('src-home-page', function(){

var resourcesToInject =  gulp.src(
    [sourcePaths.build + 'vendor/**/*.js'
        ,sourcePaths.build + 'home/**/*.js'],
    {read: false});

return gulp
    .src(youFilePath + '/file.jsp')
    .pipe($.inject(
      resourcesToInject,{
            transform: transoformResourceInclude
        }
      )
    )
    .pipe(gulp.dest('./src/main/webapp/WEB-INF/views/'));
});

function transoformResourceInclude(filePath){


var path = filePath.split('/').filter(function(slicePath){
    return slicePath != '' &&
        slicePath != 'src' && slicePath != 'main'
        && slicePath != 'webapp';
});

return  '<script src="<c:url value="/'+ path.join('/') +'" />"></script>';
}

Upvotes: 1

Droid Kree
Droid Kree

Reputation: 161

I managed to fix Gulp built process for .jsp files, implemented simple Gulp html build task, initial jsp view was called like Test.jsp.html, and then in last pipe, when all javascript and css was already injected into Test.jsp.html and then just rename it to Test.jsp.

Upvotes: 1

Related Questions