如何在gulp中为cloud9.io设置$ ip和$ host

时间:2015-04-28 17:35:23

标签: ip gulp host cloud9-ide browser-sync

我找不到在cloud9.io中设置gulp browsersync的说明。 我认为用于browsersync的设置ip和主机是错误的。我尝试在我的gulpfile.coffee中执行此操作:

require('coffee-script/register')
gulp = require('gulp')
$ = require('gulp-load-plugins')()
browserSync = require('browser-sync')

gulp.task 'sass', ->
    return gulp.src(['./sass/**/*.sass'])
        .pipe($.sourcemaps.init())
        .pipe($.sass({
            indentedSyntax: true,
            errLogToConsole: true,
            outputStyle: 'compressed'
        }))
        # .pipe($.autoprefixer('last 3 version'))
        .pipe($.sourcemaps.write('.'))
        .pipe(gulp.dest('./css'))

gulp.task 'stylus', ->
  gulp.src('./stylus/**/*.styl')
    .pipe($.sourcemaps.init())
    .pipe($.stylus())
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('./css'))

gulp.task 'server', ->
    browserSync({
        server: {
            baseDir: "./",
            port: process.env.PORT,
            host: process.env.IP  
        },
        browser: "google chrome"
    })

gulp.task 'watch', ->
    gulp.watch(['./sass/**/*.sass'], ['sass'])
    gulp.watch(['./stylus/**/*.styl'], ['stylus'])

gulp.task 'default', ['server', 'sass', 'stylus', 'watch']

当我运行命令'gulp'时:

suenot@car:~/workspace $ gulp
[17:20:06] Requiring external module coffee-script/register
[17:20:10] Using gulpfile ~/workspace/gulpfile.coffee
[17:20:10] Starting 'server'...
[17:20:10] 'server' errored after 249 μs
[17:20:10] ReferenceError: $PORT is not defined
at Gulp.<anonymous> (/home/ubuntu/workspace/gulpfile.coffee:29:19)
at module.exports (/home/ubuntu/workspace/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/home/ubuntu/workspace/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/home/ubuntu/workspace/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/home/ubuntu/workspace/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/gulp/bin/gulp.js:129:20
at process._tickCallback (node.js:442:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:929:3

我做错了什么?请帮助,抱歉我的英语不好。

1 个答案:

答案 0 :(得分:3)

Cloud9.io试图打开browser: "google chrome"。 我删除了这个字符串,并从服务器对象传输端口和主机参数,并且gulp开始成功。

gulp.task 'server', ->
browserSync({
    server: {
        baseDir: './'
    },
    port: process.env.PORT,
    host: process.env.IP
})