- Run the command
npm install
to resolve all dependencies - Create the directories:
dist/
andsrc/
- Create
src/main.js
file, and write there all browserify scripts - Run the
gulp
command - Start writing code inside the
src/
directory
Last active
January 17, 2016 23:54
-
-
Save georgymh/0582d2c075f1b7a16143 to your computer and use it in GitHub Desktop.
Basic Gulp Environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ecmaFeatures": { | |
"jsx": true | |
}, | |
"env": { | |
"browser": true, | |
"node": true, | |
"jquery": true | |
}, | |
"rules": { | |
"quotes": 0, | |
"no-trailing-spaces": 0, | |
"eol-last": 0, | |
"no-unused-vars": 0, | |
"no-underscore-dangle": 0, | |
"no-alert": 0, | |
"no-lone-blocks": 0 | |
}, | |
"globals": { | |
jQuery: true, | |
$: true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var gulp = require('gulp'); | |
var connect = require('gulp-connect'); // Runs local dev server | |
var open = require('gulp-open'); // Open a URL in a web browser | |
var browserify = require('browserify'); // Bundles JS | |
var reactify = require('reactify'); // Transforms React JSX to JS | |
var source = require('vinyl-source-stream'); // Use conventional text strams with Gulp | |
var concat = require('gulp-concat'); // Concatenates files | |
var lint = require('gulp-eslint'); // Lint JS files, including JSX | |
var config = { | |
port: 9005, | |
devBaseUrl: 'http://localhost', | |
paths: { | |
html: './src/*.html', | |
js: './src/**/*.js', | |
css: [ | |
'node_modules/bootstrap/dist/css/bootstrap.min.css', | |
'node_modules/bootstrap/dist/css/bootstrap-theme.min.css' | |
], | |
dist: './dist', | |
mainJs: './src/main.js' | |
} | |
}; | |
// Start a local development server | |
gulp.task('connect', function() { | |
connect.server({ | |
root: ['dist'], | |
port: config.port, | |
base: config.devBaseUrl, | |
livereload: true | |
}); | |
}); | |
gulp.task('open', ['connect'], function() { | |
gulp.src('dist/index.html') | |
.pipe(open({ uri: config.devBaseUrl + ':' + config.port + '/' })); | |
}); | |
gulp.task('html', function() { | |
gulp.src(config.paths.html) | |
.pipe(gulp.dest(config.paths.dist)) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('js', function() { | |
browserify(config.paths.mainJs) | |
.transform(reactify) | |
.bundle() | |
.on('error', console.error.bind(console)) | |
.pipe(source('bundle.js')) | |
.pipe(gulp.dest(config.paths.dist + '/scripts')) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('css', function() { | |
gulp.src(config.paths.css) | |
.pipe(concat('bundle.css')) | |
.pipe(gulp.dest(config.paths.dist + '/css')); | |
}); | |
gulp.task('lint', function() { | |
return gulp.src(config.paths.js) | |
.pipe(lint({config: 'eslint.config.json'})) | |
.pipe(lint.format()); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(config.paths.html, ['html']); | |
gulp.watch(config.paths.js, ['js', 'lint']); | |
}); | |
gulp.task('default', ['html', 'js', 'css', 'lint', 'open', 'watch']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ProjectName", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Georgy Marrero", | |
"license": "ISC", | |
"dependencies": { | |
"bootstrap": "^3.3.5", | |
"browserify": "^11.0.1", | |
"flux": "^2.0.3", | |
"gulp": "^3.9.0", | |
"gulp-concat": "^2.6.0", | |
"gulp-connect": "^2.2.0", | |
"gulp-eslint": "^0.15.0", | |
"gulp-open": "^1.0.0", | |
"jquery": "^2.1.4", | |
"react": "^0.13.3", | |
"react-router": "^0.13.3", | |
"reactify": "^1.1.1", | |
"vinyl-source-stream": "^1.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment