Javascript Gulp.js:如何重写相对路径?

Javascript Gulp.js:如何重写相对路径?,javascript,css,gulp,Javascript,Css,Gulp,结构: static ├── build │ ├── css │ ├── fonts │ ├── img │ └── js └── src ├── blocks ├── fonts └── img 一块gulpfile.js: var path = { build: { js: 'static/build/js', css: 'static/build/css', f

结构:

static
├── build
│   ├── css
│   ├── fonts
│   ├── img
│   └── js
└── src
    ├── blocks
    ├── fonts
    └── img
一块gulpfile.js:

var path = {
        build: {
            js: 'static/build/js',
            css: 'static/build/css',
            fonts: 'static/build/fonts',
            img: 'static/build/img'

        },
        src: {
            vendor_fonts: ['bower_components/**/*.{svg,woff,eot,ttf}', 'semantic/**/*.{svg,woff,eot,ttf}'],
            vendor_img: ['bower_components/**/*.{png,jpg,jpeg,gif}', 'semantic/**/*.{png,jpg,jpeg,gif}']

        }
};

gulp.task('vendor:img', function(){
    return gulp.src(path.src.vendor_img)
        .pipe(imagemin({
            progressive: true,
            interlaced: true,
            use: [pngguant()]
        }))
        .pipe(gulp.dest(path.build.img))
});

gulp.task('vendor:fonts', function() {
    gulp.src(path.src.vendor_fonts)
        .pipe(gulp.dest(path.build.fonts))
});
当我构建三方包(如fotorama或semantic ui)时,它们有一个相对路径——因此,main.css只有相对路径,服务器找不到它们


如何解决此问题?

如果您的
gulpfile.jss
位于根目录中,您应该能够只在路径前面加上节点全局对象
\u dirname

__dirname#
{String}
The name of the directory that the currently executing script resides in.

Example: running node example.js from /Users/mjr

console.log(__dirname);
// /Users/mjr
__dirname isn't actually a global but rather local to each module.

因此,如果你的gulpfile在你的根中,在你的路径中,那么就这样做

\uuu dirname+“/build/whatever/whatever”


如果我正确理解了您的问题,这就是问题所在。

如果您使用
gulp sass
生成.css,您将拥有
includePaths:[查找路径]
选项,该选项将搜索指定路径中的文件。