![](/img/trans.png)
[英]How transpiling nodejs Gulp-Task with gulp-babel and ignore “import”?
[英]Transpiling nodejs app with gulp-babel ignore doesn't work
我已經在gulp中創建了一個任務來轉換我的nodejs應用程序:
gulp.task('babel', function() {
return gulp.src('./**/*.js')
.pipe(babel({
ignore: [
'./gulpfile.js',
'./node_modules/**/*.js',
]
}))
.pipe(gulp.dest('./dist'));
});
問題是在編譯過程中,在dist文件夾中創建了node_modules文件夾和gulpfile。 知道為什么嗎?
gulp文件
var gulp = require('gulp');
var babel = require('gulp-babel');
var nodemon = require('gulp-nodemon');
gulp.task('babel', function() {
return gulp.src([
'./**/*.js',
'./server/config/manifest.' + (process.env['NODE_ENV'] || 'development') + '.json',
'!./gulpfile.js',
'!./node_modules/**/*.js'
])
.pipe(babel())
.pipe(gulp.dest('./dist'));
});
gulp.task('start', ['babel'], function() {
nodemon({
script: './dist/server.js',
ext: 'js jsx',
tasks: ['babel']
});
});
gulp.task('default', ['start']);
Babel的ignore
只是意味着它們將不會被轉換,但是通過該配置,gulp仍將通過管道傳遞它們。 您可能希望在gulp.src
的ignore
選項中使用這些模式。
編輯:實際上,我忘記了通過將ignore
選項傳遞給gulp.src
來排除那些模式的能力取決於您的glob
版本是多新的(請參閱我的錯誤報告 )。 另一種是!
建議使用否定的模式@ raina77ow。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.