0

I have code to inject into my webpage by gulp-inject, and I have setup my static folder to be served like this

app.use(express.static(__dirname + '/../public/'));

Then in gulpfile.js I do my magic, but my spell is broken...

var inject = require('gulp-inject');
var jsFiles = ['*.js', 'backend/**/*.js'];
gulp.task('inject', function () {
    var wiredep = require('wiredep').stream;
    var options = {
        bowerJson: require('./bower.json')
        , directory: './public/lib'
    };
    var injectSrc = gulp.src(['css/**/*.css', 'js/**/*.js'], {
        read: false
    });
    var injectOptions = {
        ignorePath: './public'
    };
    return gulp.src('./public/index.html').pipe(inject(injectSrc, injectOptions)).pipe(gulp.dest('./public/'));

How can I inject static java script and css to my html templates?

1 Answer 1

1

First in your html

<!--    inject:css-->
<!--    endinject-->
<!--    inject:js-->
<!--    endinject-->

Then in your gulpfile.js the way I found around this is removing ./ from ignorePath and adding full path to resources, like gulp.src(./public/some/folder/**/*.css)

And you should be on the good way to go :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.