【问题标题】:GULP displaying "ACCESS DENIED"GULP 显示“拒绝访问”
【发布时间】:2014-02-06 21:12:17
【问题描述】:

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

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

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

更新:我相信当我以 localhost:1337/app/index.html 和 localhost:1337/ 导航到 localhost:1337/index.html 时,我缺少一些用于欣喜若狂的配置选项以允许文件加载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);
});

【问题讨论】:

    标签: javascript node.js gulp


    【解决方案1】:

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

    要么尝试改变

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      相关资源
      最近更新 更多