【发布时间】:2021-06-19 08:18:40
【问题描述】:
我有两个不同的项目。两者都有gulpfile.js、package.json 和package-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