0

我正在使用 gulp。任务正在运行创建所需的文件夹。但是在浏览器中运行时出现Cannot GET/错误。我附上了我的项目结构的图像以及输出

吞咽

文件结构

问题(无法获取/)

我的 index.html 包含以下内容:

<!DOCTYPE html>
<html class="no-js" lang="en">
    <head>
        <title>Bootstrap 4 Layout</title>
        <meta http-equiv="x-ua-compatible" content="ie=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:400,800">
        <link rel='stylesheet' href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="/css/bootstrap.css">
        <link rel="stylesheet" href="/css/styles.css">
    </head>

    <body>
        <script src="/js/jquery.min.js"></script>
        <script src="/js/popper.min.js"></script>
        <script src="/js/bootstrap.min.js"></script>
    </body>
</html>

以下是我的 gulpfile.js

var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var sass        = require('gulp-sass');

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'])
        .pipe(sass())
        .pipe(gulp.dest("src/css"))
        .pipe(browserSync.stream());
});

// Move the javascript files into our /src/js folder
gulp.task('js', function() {
    return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/popper.js/dist/umd/popper.min.js'])
        .pipe(gulp.dest("src/js"))
        .pipe(browserSync.stream());
});

// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {

    browserSync.init({
        server: "./src"  
    });

    gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], ['sass']);
    gulp.watch("src/*.html").on('change', browserSync.reload);
});

gulp.task('default', ['js','serve']);
4

2 回答 2

0

我修好了它!只需将 index.html 放在 src 文件夹中,并将文件 style.css 重命名为“styles.css”。祝你好运!

于 2018-04-07T05:45:53.153 回答
-1

我也有这个问题。我不确定最终为我解决了什么问题。我的 Gulpfile.js 和 src 目录中的 styles.css 命名可能不一致。可能是我不知道我需要通过在命令行中输入“gulp”来启动 gulp。最初可能 gulp 没有工作,因为 gulp 没有全局安装。另外我不知道我需要 cd 进入 Gulpfile.js 所在的目录。在运行“gulp”之前。另一个问题是我需要在安装引导程序的根目录中拥有 index.html,而不是像我拥有的​​那样升级。我尝试将引导程序仅添加到 html 页面的方式不起作用。尽管如此,还是有一些东西修复了它,但我需要阅读各种文档https://getbootstrap.com/docs/4.0/getting-started/download/这些视频也有帮助。 https://www.youtube.com/watch?v=UAHfAbc8JkY https://www.youtube.com/watch?v=rTnF1U51Ie0&list=PLRAV69dS1uWRkx3Oe23_wZUylM0ecC3Hg&index=3 https://www.youtube.com/watch?v=9yQPXS7KTXM

于 2020-01-30T19:58:12.960 回答