4

我遇到了 gulp 问题,在更大程度上,babel 运行速度非常慢。处理 3 个 javascript 文件实际上需要 2-4 分钟。即使我只是运行gulp它似乎至少需要 10 秒才能启动,不知道为什么。

这是我的 gulpfile.js 的相关部分...

var gulp = require('gulp');
var $    = require('gulp-load-plugins')();
var jshint = require('gulp-jshint');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var babel = require("gulp-babel");
var browserSync = require('browser-sync').create();
var uglify = require('gulp-uglify');

gulp.task('scripts', function() {
  return gulp.src([
    'bower_components/foundation-sites/js/foundation.core.js', 
    'bower_components/foundation-sites/js/foundation.util.mediaQuery.js', 
    'js/owl.carousel.min.js'])
  .pipe(sourcemaps.init())
  .pipe(babel({
        presets: ['es2015']
  }))
  .pipe(concat('plugins.js'))
  .pipe(uglify())
  .pipe(sourcemaps.write('.'))
  .pipe(gulp.dest('./js/'));
});

这是我的 package.json 文件...

{
  "name": "foundation-sites-template",
  "version": "1.0.0",
  "description": "Basic template for a new Foundation for Sites project.",
  "main": "gulpfile.js",
  "devDependencies": {
    "babel-plugin-transform-es2015-arrow-functions": "^6.7.7",
    "babel-plugin-transform-es2015-block-scoped-functions": "^6.6.5",
    "babel-plugin-transform-es2015-block-scoping": "^6.7.1",
    "babel-plugin-transform-es2015-classes": "^6.7.7",
    "babel-plugin-transform-es2015-destructuring": "^6.6.5",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.7.7",
    "babel-plugin-transform-es2015-parameters": "^6.7.0",
    "babel-plugin-transform-es2015-shorthand-properties": "^6.5.0",
    "babel-plugin-transform-es2015-spread": "^6.6.5",
    "babel-plugin-transform-es2015-template-literals": "^6.6.5",
    "babel-preset-es2015": "^6.6.0",
    "babel-register": "^6.7.2",
    "browser-sync": "^2.12.5",
    "gulp": "^3.9.0",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-babel": "^6.1.2",
    "gulp-concat": "^2.6.0",
    "gulp-jshint": "^2.0.0",
    "gulp-load-plugins": "^1.1.0",
    "gulp-sass": "^2.1.0",
    "gulp-sourcemaps": "^2.0.0-alpha",
    "gulp-uglify": "^1.5.3",
    "jshint": "^2.9.2"
  },
  "scripts": {
    "start": "gulp",
    "build": "gulp sass"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/zurb/foundation-sites-template.git"
  },
  "bugs": {
    "url": "https://github.com/zurb/foundation-sites/issues",
    "email": "foundation@zurb.com"
  },
  "author": "ZURB <foundation@zurb.com>",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "gulp-autoprefixer": "^3.1.0"
  }
}

运行gulp scripts后需要4分钟!...

[15:41:47] Using gulpfile /Applications/MAMP/htdocs/example/wp-content/themes/example/gulpfile.js
[15:41:47] Starting 'scripts'...
[15:43:55] Finished 'scripts' after 4.13 min

有什么想法为什么这么慢?我对 npm 和 gulp 还很陌生,所以我不确定该怎么做。我在我的家用电脑上设置了另一个 Foundation 项目,它几乎可以立即编译 js。所以我肯定在这台机器上搞砸了。

4

0 回答 0