gulp inject不能从app目录

时间:2017-09-27 09:33:09

标签: gulp gulp-inject

gulpfile.js

gulp.task('inject', function() {
    var target = gulp.src('build/index.html');
    var sources = gulp.src(['build/js/**/*.js', 'build/css/**/*.css'], { read: false });

    return target.pipe(inject(sources, { ignorePath: 'build/', addRootSlash: false }))
        .pipe(gulp.dest('build'));
});

如果我输入上面的代码,它会给我下面显示的错误并且它不会复制文件。

[14:59:46] Using gulpfile ~\testApp\gulpfile.js
[14:59:46] Starting 'inject'...
[14:59:46] gulp-inject 7 files into index.html.
[14:59:46] 'inject' errored after 52 ms
[14:59:46] Error: EPERM: operation not permitted, open 'C:\Users\xyz\testApp\build\index.html'
    at Error (native)

但是当我把下面的代码放入时,它会在app.html里面的index.html中注入css / js文件。

gulp.task('inject', function() {
    var target = gulp.src('app/index.html');
    var sources = gulp.src(['build/js/**/*.js', 'build/css/**/*.css'], { read: false });

    return target.pipe(inject(sources, { ignorePath: 'build/', addRootSlash: false }))
        .pipe(gulp.dest('app'));
});

如何在构建文件夹中使用css / js文件注入来修复index.html?

0 个答案:

没有答案