问题
I would like to create 1 single javascript file out of multiple files and modules to ship as one single js file for a small library that will be used in the browser (and reuse some part on nodejs).
How can I achieve this?
(function() {
// Modules are minified
var blake = require('blakejs'); // The "entire" module in here ~350 lines...
// Other files are obfuscated
// File1.js
var first = function() {}
first.prototype.doHash = function() {}
// File2.js
var second = function() {}
second.prototype.doSomethingElse = function() {}
//OtherFile.js
//Webworker.js
}).call(this)
I'm using Javascript Obfuscator to obfuscate the script, but I'd like to apply other minification/obfuscation settings to modules, as they wouldn't need obfuscation, only minification.
gulp.task('minify', function () {
return gulp
.src('./src/file1.js')
.pipe(rename({suffix: '.min'}))
.pipe(javascriptObfuscator())
.pipe(gulp.dest('public'))
})
Is it possible?
来源:https://stackoverflow.com/questions/50596007/how-to-use-and-merge-js-modules-into-1-file