【问题标题】:Gulp doesn't create a "dist" folderGulp 不会创建“dist”文件夹
【发布时间】:2021-06-19 08:18:40
【问题描述】:

我有两个不同的项目。两者都有gulpfile.jspackage.jsonpackage-lock.json。文件夹结构完全相同。

当我在第一个项目的文件夹中启动 gulp 时,一切正常:我收到了一个包含所有内容的 dist 文件夹。

但是当我在第二个中尝试这个时,它没有。只是没有创建 dist 文件夹。我刚刚收到消息“Cannot GET /”。

我的项目结构:

project root
    #src
        fonts
        img
        js
            script.js (empty)
        scss
            style.scss (empty)
        index.html (includes <body> tag)
    node_modules
    gulpfile.js
    package-lock.json
    package.json

这是我的第二个项目的 gulpfile

let project_folder = "dist";
let source_folder = "#scr";

let path = {
    build: {
        html: project_folder + "/",
        css: project_folder + "/css/",
        js: project_folder + "/js/",
        img: project_folder + "/img/",
        fonts: project_folder + "/fonts/",
    },
    src: {
        html: source_folder + "/*.html",
        css: source_folder + "/scss/style.scss",
        js: source_folder + "/js/script.js",
        img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}",
        fonts: source_folder + "/fonts/*.ttf",
    },
    watch: {
        html: source_folder + "/**/*.html",
        css: source_folder + "/scss/**/*.scss",
        js: source_folder + "/js/**/*.js",
        img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}",
    },
    clean: "./" + project_folder + "/"
}

let { src, dest } = require('gulp'),
    gulp = require('gulp'),
    browsersync = require('browser-sync').create();

function browserSync(params) {
    browsersync.init({
        server:{
            baseDir: "./" + project_folder + "/"
        },
        port: 3000,
        notify: false
    })
}

function html() {
    return src(path.src.html)
        .pipe(dest(path.build.html))
        .pipe(browsersync.stream())
}


let build = gulp.series(html);
let watch = gulp.parallel(build, browserSync);

exports.html = html;
exports.build = build;
exports.watch = watch;
exports.default = watch;

终端

[10:57:21] Using gulpfile ~\YandexDisk\Web\Funiro\gulpfile.js
[10:57:21] Starting 'default'...
[10:57:21] Starting 'browserSync'...
[10:57:21] Starting 'html'...
[10:57:21] Finished 'html' after 31 ms
[Browsersync] Access URLs:
 --------------------------------------
       Local: http://localhost:3000
    External: http://192.168.31.89:3000
 --------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 --------------------------------------
[Browsersync] Serving files from: ./dist/

【问题讨论】:

    标签: javascript html css gulp


    【解决方案1】:

    你确定吗?

    let source_folder = "#scr";
    

    也许是“#src”?

    【讨论】:

    • 欢迎来到 StackOverFlow。请详细说明你的答案,并解释为什么你可能找到了根本原因。
    • 他写了“#scr”——这不合逻辑。他显然是指“#src”。
    • 你是对的,我承认我在第一次阅读时没有看到它。您可以通过明确地说存在拼写错误来改进您的答案,即:“#scr 和 #src 存在拼写错误”
    猜你喜欢
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    相关资源
    最近更新 更多