6

gulpfile.js

'use strict';

var gulp = require('gulp');

gulp.paths = {
  src: 'src',
  dist: 'dist',
  tmp: '.tmp',
  e2e: 'e2e'
};

require('require-dir')('./gulp');

gulp.task('build', ['clean'], function () {
    gulp.start('buildapp');
});

吞咽/server.js

'use strict';

var gulp = require('gulp');

var paths = gulp.paths;

var util = require('util');

var browserSync = require('browser-sync');

var middleware = require('./proxy');

function browserSyncInit(baseDir, files, browser) {
  browser = browser === undefined ? 'default' : browser;

  var routes = null;
  if(baseDir === paths.src || (util.isArray(baseDir) && baseDir.indexOf(paths.src) !== -1)) {
    routes = {
      '/bower_components': 'bower_components'
    };
  }

  browserSync.instance = browserSync.init(files, {
    startPath: '/',
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });
}

gulp.task('serve', ['watch'], function () {
  browserSyncInit([
    paths.tmp + '/serve',
    paths.src,
  ], [
    paths.tmp + '/serve/{app,components}/**/*.css',
    paths.src + '/{app,components}/**/*.js',
    paths.src + 'src/assets/images/**/*',
    paths.tmp + '/serve/*.html',
    paths.tmp + '/serve/{app,components}/**/*.html',
    paths.src + '/{app,components}/**/*.html'
  ]);
});

gulp.task('serve:dist', ['buildapp'], function () {
  browserSyncInit(paths.dist);
});

gulp.task('serve:e2e', ['inject'], function () {
  browserSyncInit([paths.tmp + '/serve', paths.src], null, []);
});

gulp.task('serve:e2e-dist', ['buildapp'], function () {
  browserSyncInit(paths.dist, null, []);
});

节点版本v0.10.25
npm 版本1.3.10
gulp CLI 和本地版本3.9.0
操作系统Ubuntu 14.04.2 LTS

我还正确安装了所有节点包并且没有错误。但是,如果我跑步,gulp serve
我会得到Error: spawn EACCES

我清楚地卸载了nodenpmbowergulp等并已经将它们重新安装,但它并没有解决问题。

这是我运行时的整个错误日志gulp serve

[22:15:33] Using gulpfile /media/culaste/Data/Code/sampleapp/source/gulpfile.js
[22:15:33] Starting 'styles'...
[22:15:34] gulp-inject 26 files into app.scss.
[22:15:34] Finished 'styles' after 1.24 s
[22:15:34] Starting 'inject'...
[22:15:34] gulp-inject 1 files into 404.tmpl.html.
[22:15:34] gulp-inject 1 files into 500.tmpl.html.
[22:15:35] gulp-inject 1 files into index.html.
[22:15:35] gulp-inject 105 files into 404.tmpl.html.
[22:15:35] gulp-inject 105 files into 500.tmpl.html.
[22:15:35] gulp-inject 105 files into index.html.
[22:15:35] Finished 'inject' after 668 ms
[22:15:35] Starting 'watch'...
[22:15:36] Finished 'watch' after 1.19 s
[22:15:36] Starting 'serve'...
[22:15:36] Finished 'serve' after 94 ms
[BS] Local URL: http://localhost:3000/
[BS] External URL: http://192.168.8.101:3000/
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
[BS] Watching files...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn EACCES
    at errnoException (child_process.js:988:11)
    at Process.ChildProcess._handle.onexit (child_process.js:779:34)
4

3 回答 3

8

问题是当 browserSync 尝试打开我的浏览器时,由于权限问题而引发错误。添加open: false解决了这个问题。

吞咽/server.js

browserSync.instance = browserSync.init(files, {
    startPath: '/',
    open:false,
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });

我知道现在还没有必要修复权限问题,但我认为如果您运行开发服务器时,它会自动为您打开浏览器(如果浏览器已经打开,则为新标签页)。非常感谢任何建议和/或解决方案。谢谢大家。

于 2015-06-24T13:24:57.323 回答
5

尽管在 Windows 上一切正常,但在 ubuntu 上运行它时我遇到了同样的问题,在 browsersync 初始化中设置 open:false 解决了这个问题。

browserSync.instance = browserSync.init(files, {
    startPath: '/',
    open:false,
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });
于 2015-10-26T19:23:55.210 回答
0

你的项目在哪个文件夹?由于我的应用程序安装在 /opt 下,我遇到了 EACCES 错误

您是否尝试过使用命令node server.js运行服务器?

于 2015-06-23T14:56:39.623 回答