問題描述
我正在嘗試使用 gulp 在我的 JavaScript 上運行 babel-preset-es2015,但即使在一行代碼上也需要很長時間.我最初嘗試使用大約 700 loc 的腳本包,然后使用 1 行的虛擬腳本.第一種情況大約需要 9s - 1 行 i 需要 8.38s.
I am trying to run the babel-preset-es2015 on my JavaScript using gulp, but it takes forever even on one line of code. I originally tried with my script bundle that is about 700 loc, and then with a dummy script that is 1 line. The first case takes about 9s - with 1 line i takes 8.38s.
這是我的確切設置:
package.json:
package.json:
{
"devDependencies": {
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"babel": "^6.3.26",
"babel-preset-es2015": "^6.3.13"
},
"babel": {
"presets": [ "es2015" ]
}
}
gulpfile.js:
gulpfile.js:
gulp.task('js', function () {
return gulp.src('dummyscript.js')
.pipe(concat('site.bundle.js'))
.pipe(babel())
.pipe(gulp.dest(paths.dest.scripts));
});
dummy.js:
console.log('dummy script');
我正在運行 node v4.2.4 和 npm v2.14.12.
I'm running node v4.2.4 and npm v2.14.12.
gulp-react 和 gulp-uglify 等其他操作加起來大約需要 180 毫秒.
Other operations like gulp-react and gulp-uglify all take about 180ms combined.
發(fā)生了什么事?
推薦答案
Babel 6 有很多高度嵌套的子依賴.如果你有一個非扁平的依賴樹,這可能會很慢.在您的情況下,您使用的是 npm 2,您將需要 npm dedupe
或安裝 npm@3
并重新安裝,以便您的依賴項被扁平化.
Babel 6 has many highly-nested subdependencies. This can be quite slow if you have a non-flattened dependency tree. In your case, you are using npm 2, you will need to either npm dedupe
or install npm@3
and reinstall so that your dependencies are flattened.
這篇關于Gulp babel es2015 轉換很慢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!