Last active
May 10, 2024 00:30
-
-
Save alesanabriav/3fb5f55cd9ab8b1302c4 to your computer and use it in GitHub Desktop.
This file contains 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 watchify = require('watchify'); | |
var browserify = require('browserify'); | |
var gulp = require('gulp'); | |
var source = require('vinyl-source-stream'); | |
var buffer = require('vinyl-buffer'); | |
var gutil = require('gulp-util'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var lodash = require('lodash'); | |
var reactify = require('reactify'); | |
// npm i --save-dev watchify browserify gulp vinyl-source-stream vinyl-buffer gulp-util gulp-sourcemaps lodash reactify | |
// add custom browserify options here | |
var customOpts = { | |
entries: ['./app/app.js'], | |
paths: [ | |
'./node_modules', | |
'./app/', | |
'./app/views' | |
], | |
extensions: ['jsx'] | |
}; | |
var opts = lodash.assign({}, watchify.args, customOpts); | |
var b = watchify(browserify(opts)); | |
b.transform(reactify); | |
gulp.task('js', bundle); // so you can run `gulp js` to build the file | |
b.on('update', bundle); // on any dep update, runs the bundler | |
b.on('log', gutil.log); // output build logs to terminal | |
function bundle() { | |
return b.bundle() | |
// log errors if they happen | |
.on('error', gutil.log.bind(gutil, 'Browserify Error')) | |
.pipe(source('bundle.js')) | |
// optional, remove if you don't need to buffer file contents | |
.pipe(buffer()) | |
// optional, remove if you dont want sourcemaps | |
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file | |
// Add transformation tasks to the pipeline here. | |
.pipe(sourcemaps.write('./')) // writes .map file | |
.pipe(gulp.dest('./dist')); | |
} | |
gulp.task('compile', bundle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment