我是Gulp令人难以置信的世界的新手。我已经创建了一个成功读取/写入/编译sass / css / js / html等的gulp文件。但是当我来localhost:1337
查看该网站时,我得到的只是“拒绝访问”&加载localhost:1337/index.html
以下是gulp文件(减去依赖项......)
对此有任何帮助将不胜感激! :)
更新:我相信我错过了一些ecstatic的配置选项,以便在我导航到localhost时允许加载文件:1337 / index.html as localhost:1337 / app / index.html& localhost:1337 / dist / index.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);
});
答案 0 :(得分:2)
看起来您的服务器的root设置为错误的目录。目前它被设置为__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
文件