未捕获的ReferenceError:__dirname未定义
这是 gulp 任务...
const { dest } = require('gulp')
const babel = require('babelify')
const browserify = require('browserify')
const buffer = require('vinyl-buffer')
const connect = require('gulp-connect')
const glob = require('glob')
const rename = require('gulp-rename')
const source = require('vinyl-source-stream')
const uglify = require('gulp-uglify')
function js(done) {
glob(jsConf.src, (err, files) => {
if (err) done(err)
var b = browserify({ // @updated
debug: true,
ignoreMissing: true,
// builtins: false,
commondir: false,
detectGlobals: false
})
files.forEach((file) => { b.add(file) })
b.transform(babel, { presets: ["@babel/preset-env"] })
.bundle()
.pipe(source('bundle.js'))
.pipe(dest(jsConf.build))
.pipe(buffer())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(dest(jsConf.build))
.pipe(connect.reload())
done()
})
}
使用detectGlobals:false
时,我现在遇到此__dirname
错误,否则未捕获的TypeError:fs.existsSync
不是函数
解决方案是什么?在此先感谢!