N
N
Norwood2021-10-17 14:39:28
gulp.js
Norwood, 2021-10-17 14:39:28

Why does gulp get Cannot GET /css error?

Good afternoon. CSS styles are not applied. In the debug panel, the file is connected.
616c0a008c116674366810.jpeg
but when you right-click on the link itself -> open in a new tab, it says this:
616c0a448bcaf443365715.jpeg
The file itself is not empty, but the styles are not applied.
616c0b36d8bb2768762044.jpeg
Apparently, something in the connection settings?
Here are the settings:

"use strict";
const { src, dest } = require("gulp");
const gulp = require("gulp");
const autoprefixer = require("gulp-autoprefixer");
const cssbeautify = require("gulp-cssbeautify");
const removeComments = require('gulp-strip-css-comments');
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const cssnano = require("gulp-cssnano");
const rigger = require("gulp-rigger");
const uglify = require("gulp-uglify");
const plumber = require("gulp-plumber");
const imagemin = require("gulp-imagemin");
const del = require("del");
const panini = require("panini");
const browsersync = require("browser-sync").create();



/* Paths to source/build/watch files
=========================*/

let path = {
    build: {
        html: "dist/",
        js: "dist/assets/js/",
        css: "dist/assets/css/",
        images: "dist/assets/i/"
    },
    src: {
        html: "src/*.{htm,html}",
        js: "src/assets/js/*.js",
        css: "src/assets/sass/style.scss",
        images: "src/assets/i/**/*.{jpg,png,svg,gif,ico}"
    },
    watch: {
        html: "src/**/*.{htm,html}",
        js: "src/assets/js/**/*.js",
        css: "src/assets/sass/**/*.scss",
        images: "src/assets/i/**/*.{jpg,png,svg,gif,ico}"
    },
    clean: "./dist"
};


/* Tasks
=========================*/

function browserSync(done) {
    browsersync.init({
        server: {
            baseDir: "./dist/"
        },
        port: 3000
    });
    done();
}

function browserSyncReload(done) {
    browsersync.reload();
    done();
}

function html() {
    panini.refresh();
    return src(path.src.html, { base: 'src/' })
        .pipe(plumber())
        .pipe(panini({
            root: 'src/',
            layouts: 'src/tpl/layouts/',
            partials: 'src/tpl/partials/',
            helpers: 'src/tpl/helpers/',
            data: 'src/tpl/data/'
        }))
        .pipe(dest(path.build.html))
        .pipe(browsersync.stream());
}

function css() {
    return src(path.src.css, { base: './src/assets/sass/' })
        .pipe(plumber())
        .pipe(sass().on('error', sass.logError))
      .pipe(autoprefixer({
          Browserslist: ['last 8 versions'],
          cascade: true
      }))
        .pipe(cssbeautify())
        .pipe(dest(path.build.css))
        .pipe(cssnano({
            zindex: false,
            discardComments: {
                removeAll: true
            }
        }))
        .pipe(removeComments())
        .pipe(rename({
            suffix: ".min",
            extname: ".css"
        }))
        .pipe(dest(path.build.css))
        .pipe(browsersync.stream());
}

function js() {
    return src(path.src.js, { base: './src/assets/js/' })
        .pipe(plumber())
        .pipe(rigger())
        .pipe(gulp.dest(path.build.js))
        .pipe(uglify())
        .pipe(rename({
            suffix: ".min",
            extname: ".js"
        }))
        .pipe(dest(path.build.js))
        .pipe(browsersync.stream());
}

function images() {
    return src(path.src.images)
        .pipe(dest(path.build.images));
}

function clean() {
    return del(path.clean);
}

function watchFiles() {
    gulp.watch([path.watch.html], html);
    gulp.watch([path.watch.css], css);
    gulp.watch([path.watch.js], js);
    gulp.watch([path.watch.images], images);
}

const build = gulp.series(clean, gulp.parallel(html, css, js, images));
const watch = gulp.parallel(build, watchFiles, browserSync);


// export tasks
exports.html = html;
exports.css = css;
exports.js = js;
exports.images = images;
exports.clean = clean;
exports.build = build;
exports.watch = watch;
exports.default = watch;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JavaDev, 2021-10-17
@Norwood

Remove distfrom file path. It should be like this assets/css/styles.min.css
In the browsersync settings, the server folder is specified baseDir: "./dist/", that is, this folder is localhost.
Coming out of this, you are trying to find another dist folder in the dist folder, but it is not there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question