Javascript 使用gulp时Css样式表的路径错误
我已经挣扎了一段时间,老实说,这是相当令人沮丧的 问题是: 我为我的静态网站创建了一个gulpfile,我想做的就是使用browserSync,将sass编译成css,并缩小脚本和css文件。除了一件事外,一切正常: 当我运行“gulp”时,除了位于“css/”中的de-css文件之外,所有内容都会加载。显然,服务器认为css文件(“css/style.css/”)实际上是一个文件夹 控制台错误的屏幕截图: css文件位于“css/style.css”中。Javascript 使用gulp时Css样式表的路径错误,javascript,node.js,npm,gulp,browser-sync,Javascript,Node.js,Npm,Gulp,Browser Sync,我已经挣扎了一段时间,老实说,这是相当令人沮丧的 问题是: 我为我的静态网站创建了一个gulpfile,我想做的就是使用browserSync,将sass编译成css,并缩小脚本和css文件。除了一件事外,一切正常: 当我运行“gulp”时,除了位于“css/”中的de-css文件之外,所有内容都会加载。显然,服务器认为css文件(“css/style.css/”)实际上是一个文件夹 控制台错误的屏幕截图: css文件位于“css/style.css”中。 "use strict";
"use strict";
let paths = {
script: "js/*.js",
minifiedScript: 'script.min.js',
cssPath: "css/*.css",
productionFolder: "production",
sassPath: "scss/*.scss",
htmlFiles: "*.html"
};
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
const browserSync = require('browser-sync').create();
const cssMin = require('gulp-css');
const sass = require('gulp-sass');
const inject = require('gulp-inject');
const rename = require("gulp-rename");
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: "./"
}
});
});
gulp.task('sass', function () {
return gulp.src(paths.sassPath)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'))
.pipe(browserSync.stream());
});
gulp.task('index', function () {
var target = gulp.src('index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src([paths.script,paths.cssPath], {read: false});
return target.pipe(inject(sources))
.pipe(gulp.dest(''));
});
gulp.task('cssMinify', function(){
return gulp.src(paths.cssPath)
.pipe(cssMin())
.pipe(gulp.dest(paths.productionFolder + "/minified css"))
.pipe(browserSync.stream());
});
gulp.task('clean', function() {
// You can use multiple globbing patterns as you would with `gulp.src`
return del(['build']);
});
gulp.task('scripts', ['clean'], function() {
// Minify and copy the JS file
return gulp.src(paths.script)
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(concat(paths.minifiedScript))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.productionFolder + "/minified JS"));
});
gulp.task('jsMinify:watch', function() { gulp.watch(paths.script, ['scripts']) });
gulp.task('sass:watch', function() { gulp.watch(paths.sassPath, ['sass']) });
gulp.task('cssMinify:watch', function() { gulp.watch(paths.cssPath, ['cssMinify']) });
gulp.task('html:watch', function() { gulp.watch(paths.htmlFiles).on('change', browserSync.reload) });
gulp.task('default', ['sass', 'index', 'cssMinify', 'clean', 'html:watch', 'jsMinify:watch', 'sass:watch', 'cssMinify:watch','browserSync', 'scripts']); // DEVELOPMENT
如果将baseDir从
“/”
更改为“
”,会发生什么情况??另外,在我的gulpfile中,对于gulp.dest,它们的前缀不是/
,因此gulp.dest('css')
而不是gulp.dest('./css')
。html中的css链接是什么?还有,您的问题是任务的运行顺序吗?因为它们是并行运行的,不一定按照默认任务中列出它们的顺序运行。如果将baseDir从“/”
更改为“
”,会发生什么情况??另外,在我的gulpfile中,对于gulp.dest,它们的前缀不是/
,因此gulp.dest('css')
而不是gulp.dest('./css')
。html中的css链接是什么?还有,您的问题是任务的运行顺序吗?因为它们是并行运行的,不一定按照默认任务中列出它们的顺序运行。