How to remove path prefix in gulp injected script paths?

1.4k Views Asked by At

I've used maven and gulp together. in maven, the injection task of gulp invokes during packaging the jar. I've placed static files in src/main/resources/static/ for the spring boot structure in the project. after packaging the jar, index.html file is something like this:

<!-- build:js js/app.js -->
<!--inject:js -->
<script src="src/main/resources/static/app/.................js"></script>
<!--endinject -->
<!--endbuild -->

My question is how to remove src/main/resources/static prefix in the script src tags?

Below code is the injection task in gulp.file.js:

gulp.task('injection', function () {
    var wiredep = require('wiredep').stream;
    var angularFilesort = require('gulp-angular-filesort');
    var option = gulpConfig.getWireDepOptions();

    return gulp
        .src(gulpConfig.config.indexPage)
        .pipe(wiredep(option))
        .pipe($.inject(
            gulp.src(gulpConfig.config.jsSources.injectable)
                .pipe(angularFilesort()), {ignorePath: '', addRootSlash: false}))
        // .pipe(gulp.dest('./src/main/resources/static/'));
        .pipe(gulp.dest('./src/main/resources/static/'));
});

and configuration in gulp.config.js :

var config = {
    buildPath:'',
    styles:[],
    indexPage: client + "index.html",
    browserSync:{
        proxy: 'localhost:' + port,
        port: 3000,
        files: ['**/*.*'],
        ghostMode: { // these are the defaults t,f,t,t
            clicks: true,
            location: false,
            forms: true,
            scroll: true
        },
        logLevel: 'debug',
        logPrefix: 'gulp-patterns',
        notify: true,
        reloadDelay: 1000
    },
    bower: {
        json: require('./bower.json'),
        directory: client+'vendors',
        ignorePath: './../../'
    },
    jsSources: {
        client: client + "app/**/*.js",
        exclude: "!vendors/**/*.js",
        sundry: ['./gulpfile.js', './gulpfile.config.js'],
        injectable: [
            scriptPath + '/quick-sidebar.js',
            scriptPath + '/demo.js',
            scriptPath + '/layout.js',
            scriptPath + '/metronic.js',
            client + 'app/**/*.module.js',
            client + 'app/**/*.js',
            '!' + client + '/app/**/*.spec.js',
        ]
    },
};
2

There are 2 best solutions below

0
Pooya On BEST ANSWER

By setting ignorePath in gulp.file.js with src/main/resources/static it will removes the prefix path in index.html

0
Mahtab Alam On

After struggling a lot below one worked

    gulp.src(['app/client/public/index.html']) 
     .pipe(inject(gulp.src(['app/client/public/js/**/*.js','app/client/public/app.js'],{read: false} ),
      {addRootSlash : true,ignorePath:'/app/client/public'}))