0

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

If i put the above code it gives me the error shown below and it does not copy file.

[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)

But when I put the below code, it injects css/js file in index.html inside app directory.

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

How to acheieve index.html with css/js file injection in build folder?

4

0 回答 0