0

我是 Gulp 令人难以置信的世界的新手。我创建了一个 gulpfile,它成功地读取/写入/编译 sass/css/js/html 等。但是当我查看该站点时,localhost:1337我得到的只是加载时“访问被拒绝”和“找不到文件”localhost:1337/index.html

下面是 gulp 文件(减去依赖项......)

对此的任何帮助将不胜感激!:)

更新:我相信当我以 localhost:1337/app/index.html 和 localhost:1337/dist/index 导航到 localhost:1337/index.html 时,我缺少一些配置选项让我欣喜若狂地允许文件加载.html 在浏览器中加载良好。

// options
var config = {
    html_src:           "app/**/*.html",
    sass_src:           "app/assets/styles/main.scss",
    js_src:             "app/assets/scripts/**/*.js",
    css_dest:           "dist/assets/styles",
    js_dest:            "dist/assets/styles",
    js_concat_target:   "main.js",
    http_port:          "1337",
    livereload_port:    "35729"
};

// end config || begin tasks

gulp.task('styles', function() {
    gulp.src(config.sass_src)
        .pipe(sass({style:"expanded" }))
        .pipe(autoprefixer("last 2 version", "safari 5", "ie 8", "ie 9", "opera 12.1", "ios 6", "android 4"))
        .pipe(gulp.dest(config.css_dest))
        .pipe(rename({ suffix: ".min" }))
        .pipe(minifycss())
        .pipe(gulp.dest(config.css_dest))
        .pipe(livereload(server))
        //.pipe(notify({ message:"styles task complete" }));
});

gulp.task('scripts', function() {
    gulp.src(config.js_src)
        .pipe(jshint(/* ".jshintrc" */))
        .pipe(jshint.reporter('default'))
        .pipe(concat(config.js_concat_target))
        .pipe(gulp.dest(config.js_dest))
        .pipe(rename({ suffix: ".min" }))
        .pipe(uglify())
        .pipe(gulp.dest(config.js_dest))
        .pipe(livereload())
        //.pipe(notify({ message: "scripts task complete" }));
});

gulp.task('html', function() {
    gulp.src(config.html_src)
        .pipe(gulp.dest('dist/'))
        .pipe(livereload())
});

gulp.task('clean', function() {
    gulp.src([config.css_dest, config.js_dest], { read: false })
        .pipe(clean());
});

gulp.task('default', ['clean'], function() {
    server.listen(config.livereload_port);
    http.createServer(ecstatic({ root: __dirname} )).listen(config.http_port);
        gutil.log(gutil.colors.yellow('HTTP Server running on port ' + config.http_port));
    gulp.watch(config.sass_src, ['styles'])._watcher.on('all', livereload);
    gulp.watch(config.js_src, ['scripts'])._watcher.on('all', livereload);
    gulp.watch(config.html_src, ['html'])._watcher.on('all', livereload);
});
4

1 回答 1

2

看起来您的服务器的根目录设置为错误的目录。目前它被设置为__dirname您的 gulpfile 所在的目录,但您的文件正在输出到dist子目录。

要么尝试改变

http.createServer(ecstatic({root: __dirname})).listen(config.http_port);

http.createServer(ecstatic({root: 'dist'})).listen(config.http_port);

或访问您的index.html文件localhost:1337/dist/index.html

于 2014-02-06T21:31:57.863 回答