Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GulpWebServer:链接到css&x27;如果在html文件夹之外,则无法工作?_Html_Css_Server_Gulp - Fatal编程技术网

GulpWebServer:链接到css&x27;如果在html文件夹之外,则无法工作?

GulpWebServer:链接到css&x27;如果在html文件夹之外,则无法工作?,html,css,server,gulp,Html,Css,Server,Gulp,如果我有一个html文件并链接到同一文件夹或子文件夹中的css文件,那么运行gulp webserver时会包含css 但是如果我把css文件放在html文件夹之外,它就不会被包括在内 例如,如果css在同一个文件夹中,我可以写: <link rel="stylesheet" href="style.css"> src是服务器的根目录,由于安全问题,您无法访问它的父目录 gulpwebserver确实支持中间件,例如service static var serveStatic =

如果我有一个html文件并链接到同一文件夹或子文件夹中的css文件,那么运行gulp webserver时会包含css

但是如果我把css文件放在html文件夹之外,它就不会被包括在内

例如,如果css在同一个文件夹中,我可以写:

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

src
是服务器的根目录,由于安全问题,您无法访问它的父目录

gulpwebserver
确实支持中间件,例如
service static

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

gulp.task('webserver', function() {
    gulp.src(htmlFolder)
    .pipe(webserver({
        livereload: true,
        open: true,
        middleware: [serveStatic(__dirname + '/builds')]
    }));
});

根目录
是它能走的最远的地方:。
<link rel="stylesheet" href="../../builds/development/postcss/css/style.css">
gulp.task('webserver', function() {
    gulp.src(htmlFolder)
    .pipe(webserver({
        livereload: true,
        open: true
    }));
});
var serveStatic = require('serve-static');

gulp.task('webserver', function() {
    gulp.src(htmlFolder)
    .pipe(webserver({
        livereload: true,
        open: true,
        middleware: [serveStatic(__dirname + '/builds')]
    }));
});