Last active
April 30, 2023 07:50
-
-
Save VivaRado/5bc16502ebb94d4b4506619cfe75e3c0 to your computer and use it in GitHub Desktop.
Browserify CMD vs GULP
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
module.exports = req_a; | |
function req_a() { | |
} |
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
const gulp = require('gulp'); | |
const nodemon = require('nodemon'); | |
const b = require('browserify'); | |
const source = require('vinyl-source-stream'); | |
const buffer = require('vinyl-buffer'); | |
const rename = require('gulp-rename'); | |
const child = require('child_process'); | |
var _src_a = `${__dirname}/src/index_funcs.js`; | |
var _dst_a = `${__dirname}/dst/funcs.js`; | |
// "browserify src/index_paint > dst/funcs.js" | |
gulp.task('browserify_cmd', (done) => { | |
var cmp_a = child.spawn('browserify', [ _src_a, '-o', _dst_a ], { stdio: 'inherit'}); | |
cmp_a.on('exit', (exitCode) => { | |
done() | |
}); | |
}); | |
var browserifier = function (done) { | |
b({ | |
entries: _src_a, | |
debug: false, | |
fullpath: false | |
}).bundle() | |
.pipe(source('./src/index_funcs.js')) | |
.pipe(buffer()) | |
.pipe(rename('funcs.js',{dirname: ''})) | |
.pipe(gulp.dest('./dst')); | |
if (done) { | |
done() | |
} | |
}; | |
gulp.task('browserify', browserifier); | |
gulp.task('watch', function () { | |
nodemon({ | |
script: 'server.js', | |
env: { | |
'PORT': 6006 | |
}, | |
//args: ['--bundle'], | |
watch: ['gulpfile.js', 'src/**/*.*'], | |
stdout: false | |
}) | |
.on('restart', function() { | |
browserifier(function(){ | |
}); | |
}) | |
}); | |
gulp.task('default', gulp.series(browserifier, 'watch')); |
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
var req_a = require('./app/file_a'); // in src/app/file_.js | |
window.yourFunc = function () { | |
req_a() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment