我的gulpfile.js
包含ff:
'use strict'
// All add-ons required
const gulp = require('gulp')
const uglify = require('gulp-uglify')
const sourcemaps = require('gulp-sourcemaps')
const csso = require('gulp-csso')
const htmlmin = require('gulp-htmlmin')
const concat = require('gulp-concat')
const rename = require('gulp-rename')
const del = require('del')
// Tasks
// Minifies HTML
gulp.task('pages', function() {
return gulp.src('src/*.html')
.pipe(htmlmin({ collapseWhitespace: true, ignoreCustomComments: '[ /!/ ]', removeComments: true }))
.pipe(gulp.dest('./dist/'))
})
// Copy NPM frameworks to vendor/
gulp.task('vendor', function() {
return gulp.src(['./node_modules/materialize-css/dist/css/materialize.min.css', './node_modules/materialize-css/dist/js/materialize.min.js'], { base: 'node_modules' })
.pipe(gulp.dest('./dist/vendor/'))
})
// Minifies CSS
gulp.task('styles', function() {
return gulp.src('./src/assets/styles/*.css')
.pipe(sourcemaps.init())
// Minify the file
.pipe(csso())
// Concatenate all CSS files to 'styles.min.css' then Output
.pipe(concat('design'))
.pipe(rename({ suffix: '.min.css' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/css/'))
})
// Minifies JS Files
gulp.task('scripts', function() {
return gulp.src('./src/assets/js/*.js')
// Create a sourcemap
.pipe(sourcemaps.init())
// Minify the file
.pipe(uglify())
// Concatenate all js files to 'app.min.js' then Output
.pipe(concat('asset'))
.pipe(rename({ suffix: '.min.js' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/js/'))
})
// Minifies the main Renderer file `main.js`
gulp.task('renderer', function() {
return gulp.src('./src/main.js')
// Create a sourcemap
.pipe(sourcemaps.init())
// Minify the file
.pipe(uglify())
// Concatenate all js files to 'app.min.js' then Output
.pipe(concat('app'))
.pipe(rename({ suffix: '.min.js' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'))
})
// Cleans the dist/ folder if not empty
// to avoid conflicts per gulp runs
gulp.task('clean', function() {
return gulp.src('dist/*')
.pipe(del('./dist/*'))
})
// Default Build
gulp.task('default',
gulp.series('clean', gulp.parallel('pages', 'vendor', 'styles', 'scripts', 'renderer')))
每次我运行gulp
或gulp [task]
时,它只会抛出一些对我来说没有意义的错误:
[19:43:57] Using gulpfile ~\Desktop\LAN\Workspace\Code\secret [revamp]\gulpfile.js
C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\lib\taskTree.js:4
return Object.keys(tasks)
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at module.exports (C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\lib\taskTree.js:4:17)
at logTasks (C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:134:14)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:127:14
at internalTickCallback (internal/process/next_tick.js:70:11)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:763:11)
at startup (internal/bootstrap/node.js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
已经尝试过this solution,但不幸的是我没有解决问题。
PS
我的gulp
版本是"gulp": "^4.0.0"
答案 0 :(得分:0)
遇到了同样的问题,发现这可能与您的 IDE 中的设置有关,例如 PHPStorm。就我而言,PHPStorm 使用的是 Gulp 3.7 解释器,而不是由 NPM 安装的本地 4.0。
转到运行 » 编辑配置 » Gulp