如何在gull注入的脚本路径中删除路径前缀

How to remove path prefix in gulp injected script paths?

本文关键字:路径 删除 前缀 脚本 gull 注入      更新时间:2023-09-26

我把maven和gullow一起用过。在maven中,gulp的注入任务在封装jar时调用。我已经在src/main/resources/static/中为项目中的spring-boot结构放置了静态文件。打包jar后,index.html文件如下所示:

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

我的问题是如何删除脚本src标记中的src/main/resources/static前缀?

下面的代码是gull.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/'));
});

和gull.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',
        ]
    },
};

通过使用src/main/resources/static在gull.file.js中设置ignorePath,它将删除index.html 中的前缀路径

在一个工作下挣扎了很多之后

    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'}))