1

If I have a html file and link to a css file that is in the same folder or a subfolder, the css is included when running gulp webserver.

But if I have the css file outside the html-folder, it doesn't get included.

So for example, if the css is in the same folder, I can write:

 <link rel="stylesheet" href="style.css">

and it will work. If I place it outside in the parent folder, and link to it:

 <link rel="stylesheet" href="../style.css">

it doesn't work. Is this a problem with gulp webserver or have I overlooked something? I would like to have the css at a diefferent place, like this:

<link rel="stylesheet" href="../../builds/development/postcss/css/style.css">

In the browser, it says "failed to load resource".

Here is the webserver task:

gulp.task('webserver', function() {
    gulp.src(htmlFolder)
    .pipe(webserver({
        livereload: true,
        open: true
    }));
});
1

2 Answers 2

2

The src is the root of the server, you can't access it's parent due to security issues.

gulp-webserver does support middleware, such as serve-static.

var serveStatic = require('serve-static');

gulp.task('webserver', function() {
    gulp.src(htmlFolder)
    .pipe(webserver({
        livereload: true,
        open: true,
        middleware: [serveStatic(__dirname + '/builds')]
    }));
});
Sign up to request clarification or add additional context in comments.

Comments

0

I think the better way is to use the "browserSync" in nowadays.

function do_browserSync(done) {
    browserSync({
        server: {
            baseDir: '.'
        },
        startPath: 'debug/index.html',
        port: 8000,
        open: true,
        notify: false
    });
    done();
};

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.