How to use and merge JS modules into 1 file?

青春壹個敷衍的年華 提交于 2019-12-11 08:36:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!