I have a javascript library intented to work in the browser, that I package with the following kind of gulpfile:
gulp.task("build", function() {
return gulp.src(sourceFiles)
.pipe(sourcemaps.init())
.pipe(concat("lib.js"))
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/"));
});
I want to start migrating this library to ES2015, using Babel.
For now, each source file in the src/ folder represents a module and is written using the following convention.
In src/MyModule.js
:
MyLib.MyModule = (function () {
var module = {};
// code here...
return module;
})();
I want to migrate these scripts to ES2015-style modules, but I still want my releases to contain a single script (here lib.js
). The consumers of my library would then load my modules using AMD implementations (e.g. require.js).
Is it possible to achieve such a thing? How would I do this?
EDIT:
I don't need my modules to remain nested like they currently are (Foo.Bar.Baz
). But I do need my modules to be compatible with Flow.