javascript - running gulp & express simultaneously -
set gulp, set node, express. i'm running gulp, it's watching tasks. set express, it's running on port 3001, gulp 3000 default?
i go localhost:3000, see index.html, go localhost:3001 (the express port) , see index.html, without css. going on here , how can work both on 1 port? possible? keep gulp , node server running? new js.
here's files:
package.json
{ "name": "hour-hour", "version": "0.0.1", "private": true, "description": "find best local happy hours , drink specials near you.", "main": "server.js", "scripts": { "test": "echo \"error: no test specified\" && exit 1" }, "author": "corey maret", "license": "isc", "devdependencies": { "browser-sync": "^2.12.3", "del": "^2.2.0", "express": "^4.13.4", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.0", "gulp-plumber": "^1.1.0", "gulp-rename": "^1.2.2", "gulp-sass": "^2.3.1", "gulp-uglify": "^1.5.3", "jshint": "^2.9.2" }, "dependencies": { "express": "^4.13.4", "express-handlebars": "^3.0.0", "gulp-plumber": "^1.1.0" } }
server.js
var express = require('express'), app = express(); var router = express.router(); app.use(express.static('public')); app.get('/', function (req, res) { res.sendfile(__dirname + '/index.html'); }); app.listen(3001, function() { console.log('i\'m listening...') })
gulpfile
/* required */ var gulp = require('gulp'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var sass = require('gulp-sass'); var browsersync = require('browser-sync').create(); var reload = browsersync.reload; var plumber = require('gulp-plumber'); var autoprefixer = require('gulp-autoprefixer'); /* scripts task */ gulp.task('scripts', function(){ gulp.src(['app/js/**/*.js', '!app/js/**/*min.js']) .pipe(plumber()) .pipe(rename({suffix:'.min'})) .pipe(uglify()) .pipe(gulp.dest('app/js')) .pipe(reload({stream:true})); }); /* sass task */ gulp.task('sass', function(){ return gulp.src('app/scss/**/*.scss') .pipe(plumber()) .pipe(sass()) .pipe(autoprefixer('last 2 versions')) .pipe(gulp.dest('app/css')) .pipe(reload({stream:true})); }); /* html task */ gulp.task('html', function(){ gulp.src('app/**/*.html') .pipe(plumber()) .pipe(reload({stream:true})); }); /* browser-sync task */ gulp.task('browser-sync', function(){ browsersync.init({ server:{ basedir: "./app/" } }); }); /* watch task */ gulp.task('watch', function(){ gulp.watch('app/js/**/*.js', ['scripts']); gulp.watch('app/scss/**/*.scss', ['sass']); gulp.watch('app/**/*.html', ['html']); }) /* default */ gulp.task('default', ['scripts', 'sass', 'html', 'browser-sync', 'watch']);
you have run browser-sync
in proxy mode:
gulp.task('browser-sync', function() { browsersync.init({ proxy: "localhost:3001" }); });
now, run server.js first , gulp, , you'll have 1 server running (browser-sync give url use).
Comments
Post a Comment