This project is no longer actively maintained. Mostly, because we use Webpack in our projects now. I am happy to review incoming PRs, though. If you would like to become maintainer, please contact me. – @normanrz
- Trace all dependencies of an AMD module
- Stream-friendly: Pipe in files and get an ordered stream of files out. No need for writing on disk in between.
- Support for precompilation of source files (ie. CoffeeScript)
- Wraps non-AMD dependencies
- Supply a custom loader for on-demand loading
- Leaves concatenation and minification to your preferred choice of modules
- gulp-sourcemaps support
var gulp = ;var amdOptimize = ;var concat = ;gulp;
This aims to be an alternative to the powerful r.js optimizer, but made for a streaming environment like gulp. This implementation doesn't operate on the file system directly. So, there's no need for complicated setups when dealing with precompiled files. Also, this module only focuses on tracing modules and does not intend replace a full-fletched build system. Therefore, there might be tons of use cases where r.js is a better fit.
$ npm install amd-optimize
paths :"backbone" : "../bower_components/backbone/backbone""jquery" : "../bower_components/jquery/jquery"
map :// Replace underscore with lodash for the backbone module"backbone" :"underscore" : "lodash"
shim :// Shimmed export. Specify the variable name that is being exported."three" :exports : "THREE"// Shimmed dependecies and export"three.color" :deps : "three"exports : "THREE.ColorConverter"// Shimmed dependencies"bootstrap" : "jquery"
Supply a filepath (can be a glob) or a gulp stream to your config file that lists all your paths, shims and maps.
true it will trace
require() dependencies inside of top-level
define() calls. Usually, these nested dependencies are considered dynamic or runtime calls, so it's disabled by default.
Would trace both
true all files that you have declared a shim for and don't have a proper
define() call will be wrapped in a
// Originalvar test = "Test";// Output;// Shim configshim :test :exports : "test"
true all files that you combine will not be altered from the source, should be used for outputted files to match the original source file, good for debugging and inline sourcemaps. A good code minifier or uglify will remove comments and strip new lines anyway.
WIP. Subject to change.
amdOptimize(), but won't accept an input stream. Instead it will rely on loading the files by itself.
- Check the input stream.
- Look for files with the default loader and
- Look for files with the custom loader and its transform streams.
- Give up.
- gulp-concat: Concat the output files. Because that's the whole point of module optimization, right?
var concat = ;gulp;
- gulp-uglify: Minify the output files.
var uglify = ;gulp;
var coffee = ;gulp;
- gulp-if: Conditionally pipe files through a transform stream. Useful for CoffeeScript precompilation.
var gif = ;gulp;
var eventStream = ;var order = ;eventStream;
- No RequireJS plugins. Except for the
- No circular dependencies
- Install npm dev dependencies
- Install gulp globally
npm install -g gulp
MIT © scalable minds 2014