Javascript 狼吞虎咽';启动';创建错误而不是创建';地区';文件夹
启动Gulp start时,需要创建一个Dist文件夹,并在包含的依赖项上开始观察,但实际上,它会在“css”concat上出错Javascript 狼吞虎咽';启动';创建错误而不是创建';地区';文件夹,javascript,gulp,Javascript,Gulp,启动Gulp start时,需要创建一个Dist文件夹,并在包含的依赖项上开始观察,但实际上,它会在“css”concat上出错 我已尝试手动创建Dist文件夹 在src目录中创建了test.css文件 这没什么区别。同样的错误会弹出,其他情况不会发生 我下面的教程是: 预期结果见时间指数37:48。这是我的结果 错误 $gulp start[05:06:38]使用gulpfile ~/OneDrive/~webDev/chazSutherland/gulpfile.js[05:06:38]
- 我已尝试手动创建Dist文件夹
- 在src目录中创建了test.css文件
const gulp = require('gulp');
const gulpConcat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const scripts = require('./scripts');
const styles = require('./styles');
var devMode = false;
gulp.task('css', function(){
gulp.src(styles)
.pipe(concat('main.css'))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('js', function(){
gulp.src(scripts)
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('html', function(){
gulp.src('./src/html/**/*.html')
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('build', function(){
gulp.start(['css', 'js', 'html']);
});
gulp.task('browser-sync', function(){
browserSync.init(null, {
open: false,
server: {
baseDir: 'dist'
}
});
});
gulp.task('start', function(){
devMode = true;
gulp.start(['build', 'browser-sync']);
gulp.watch(['./src/css/**/*.css'], ['css']);
gulp.watch(['./src/js/**/*.js'], ['js']);
gulp.watch(['./src/html/**/*.html'], ['html']);
});
package.json
{
"name": "chazsutherland",
"version": "1.0.0",
"description": "Practice practice practice!!",
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "(https://github.com/CyberGolem/learningGulp.com)"
},
"keywords": [
"npm"
],
"author": "Chaz Sutherland",
"license": "ISC",
"dependencies": {
"angular": "^1.6.2",
"angular-route": "^1.6.2"
},
"devDependencies": {
"browser-sync": "^2.18.7",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1"
}
}
[
"./src/css/**/*.css"
]
[
"./node_modules/angular/angular.js",
"./node_modules/angular-route/angular-route.js",
"./src/js/**/*.js"
]
styles.json
{
"name": "chazsutherland",
"version": "1.0.0",
"description": "Practice practice practice!!",
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "(https://github.com/CyberGolem/learningGulp.com)"
},
"keywords": [
"npm"
],
"author": "Chaz Sutherland",
"license": "ISC",
"dependencies": {
"angular": "^1.6.2",
"angular-route": "^1.6.2"
},
"devDependencies": {
"browser-sync": "^2.18.7",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1"
}
}
[
"./src/css/**/*.css"
]
[
"./node_modules/angular/angular.js",
"./node_modules/angular-route/angular-route.js",
"./src/js/**/*.js"
]
scripts.json
{
"name": "chazsutherland",
"version": "1.0.0",
"description": "Practice practice practice!!",
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "(https://github.com/CyberGolem/learningGulp.com)"
},
"keywords": [
"npm"
],
"author": "Chaz Sutherland",
"license": "ISC",
"dependencies": {
"angular": "^1.6.2",
"angular-route": "^1.6.2"
},
"devDependencies": {
"browser-sync": "^2.18.7",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1"
}
}
[
"./src/css/**/*.css"
]
[
"./node_modules/angular/angular.js",
"./node_modules/angular-route/angular-route.js",
"./src/js/**/*.js"
]
在您的代码中,您需要gulp concat作为
const gulpConcat=require('gulp-concat')代码>
但后来您尝试将其用作.pipe(concat('main.css'))
错误告诉您,concat
没有在第14行定义,这是正确的,因为您定义的是gulpConcat
,而不是concat
因此,对于解决方案更改:
const gulpConcat=require('gulp-concat')代码>到
const concat=require('gulp-concat')代码>您的错误告诉您原因:
ReferenceError:Gulp中未定义concat
您正在尝试引用脚本中未定义的concat
变量
const gulpConcat = require('gulp-concat');
// ...
.pipe(concat('main.css'))
// ...
.pipe(concat('scripts.js'))
只需将gulpConcat
常量重命名为concat
,错误将被修复。在你提到的视频中