如何删除 gulp 注入脚本路径中的路径前缀?
How to remove path prefix in gulp injected script paths?
我一起使用过 maven 和 gulp。在 Maven 中,gulp 的注入任务在打包 jar 期间调用。我已将静态文件放在 src/main/resources/static/
中,用于项目中的 spring 引导结构。打包 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
前缀?
下面的代码是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/'));
});
和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',
]
},
};
通过将 gulp.file.js 中的 ignorePath 设置为 src/main/resources/static
,它将删除 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'}))
我一起使用过 maven 和 gulp。在 Maven 中,gulp 的注入任务在打包 jar 期间调用。我已将静态文件放在 src/main/resources/static/
中,用于项目中的 spring 引导结构。打包 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
前缀?
下面的代码是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/'));
});
和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',
]
},
};
通过将 gulp.file.js 中的 ignorePath 设置为 src/main/resources/static
,它将删除 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'}))