javascript - 如何从我的 Babel 编译代码中删除 transform typeof 符号代码?
问题描述
我最近将 babel 添加到我的 gulpfile 中,这样我就可以开始在 ES6 中编写代码了。代码按预期编译,但我注意到以下代码行在多个位置添加到已编译的 JS 文件中。我认为我不需要它,因此想删除它:
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
我试过的:
在gulpfile.babel.js
,里面createBuildTask()
,我presets
这样设置:'presets': [['env', {'exclude': ['transform-typeof-symbol']}]]
...这导致在 gulp 构建期间返回以下错误:
Invalid Option: The plugins/built-ins 'transform-typeof-symbol' passed to the 'exclude' option are not valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env
这是删除的正确方法,还是我应该以不同的方式处理它?下面我已经包括了我的相关部分package.json
,以及gulpfile.babel.js
。
package.json (包括dev , devDependencies )
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^7.2.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"del": "^2.2.2",
"eslint": "^6.6.0",
"gulp": "^4.0.2",
"gulp-babel": "^7.0.1",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^6.0.0",
"gulp-rename": "^1.2.2",
"gulp-terser": "^1.2.0"
},
"dependencies": {
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"babel-polyfill": "^6.26.0",
"lodash": "^4.17.15"
}
gulpfile.babel.js
var gulp = require('gulp');
var babel = require('gulp-babel');
var concat = require('gulp-concat');
var del = require('del');
var eslint = require('gulp-eslint');
var rename = require('gulp-rename');
var terser = require('gulp-terser');
function createBuildTask() {
var sourceArray = [
'common/*.js',
'nep/api/*.js',
'nep/controller/*.js',
'nep/legacy/*.js',
'nep/nep-sat.js'
];
return function () {
return gulp.src(sourceArray, {'allowEmpty': true})
.pipe(babel({
'presets': ['env'],
'plugins': ['transform-remove-strict-mode']
}))
.pipe(concat('nep-built-sat.js'))
.pipe(gulp.dest('nep/dist'))
.pipe(terser())
.pipe(rename({
'extname': '.min.js'
}))
.pipe(gulp.dest('nep/dist'));
};
}
function createLintTask(destination) {
return function () {
return gulp.src(destination + '/' + destination + '-sat.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
};
}
gulp.task('lint-nep', createLintTask('nep'));
gulp.task('build-nep', createBuildTask());
gulp.task('nep', gulp.series('lint-nep', 'build-nep'));
gulp.task('default', gulp.series('lint-nep', 'build-nep'));
gulp.task('clean', (done) => {
del.sync(['*/dist']);
done();
});
解决方案
推荐阅读
- python - 尝试删除每个单词的标点符号列表 - 最终删除所有标点符号
- foreign-keys - 具有外键的数据库:描绘前向与后向关系的好方法?
- xamarin - Xamarin:修复链接器错误(使用 FFImageLoading 和 SDWebImage)
- linux - 如何改进(缩短时间)我的 shell 脚本代码?我正在尝试将文件夹分成几个较小的文件夹
- ruby-on-rails - Rails 嵌套强参数,如何使用?
- amazon-dynamodb - 一旦有主键,提供的键元素与架构错误不匹配
- git - 自动解决包含自动生成代码的特定文件夹中的 Git 合并冲突
- javascript - 如何找到给定数组中总和为零的子数组的数量
- html - 水平图像之间的响应背景线
- c - 在 C 中使用带有数组作为输入的函数