在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):scalableminds/amd-optimize开源软件地址(OpenSource Url):https://github.com/scalableminds/amd-optimize开源编程语言(OpenSource Language):CoffeeScript 61.7%开源软件介绍(OpenSource Introduction):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 amd-optimize
Features
Examplevar gulp = require("gulp");
var amdOptimize = require("amd-optimize");
var concat = require('gulp-concat');
gulp.task("scripts:index", function () {
return gulp.src("src/scripts/**/*.js")
// Traces all modules and outputs them in the correct order.
.pipe(amdOptimize("main"))
.pipe(concat("index.js"))
.pipe(gulp.dest("dist/scripts"));
}); MotivationThis 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. Installation$ npm install amd-optimize APIamdOptimize(moduleName, [options])moduleNameType: options.pathspaths : {
"backbone" : "../bower_components/backbone/backbone",
"jquery" : "../bower_components/jquery/jquery"
} options.mapmap : {
// Replace underscore with lodash for the backbone module
"backbone" : {
"underscore" : "lodash"
}
} options.shimshim : {
// 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"]
} options.configFileType: Supply a filepath (can be a glob) or a gulp stream to your config file that lists all your paths, shims and maps. amdOptimize.src("index", {
configFile : "src/scripts/require_config.js"
});
amdOptimize.src("index", {
configFile : gulp.src("src/scripts/require_config.coffee").pipe(coffee())
}); options.findNestedDependenciesType: If Would trace both define("router", [], function () {
return {
"/home" : function () {
require(["controllers/home"]);
},
...
}
}) options.baseUrloptions.excludeoptions.includeoptions.wrapShimType: If // Original
var test = "Test";
// Output
define("test", [], function () {
var test = "Test";
return test;
});
// Shim config
shim : {
test : {
exports : "test"
}
} options.preserveFilesType: If options.loaderWIP. Subject to change. amdOptimize.src(
"index",
loader : amdOptimize.loader(
// Used for turning a moduleName into a filepath glob.
function (moduleName) { return "src/scripts/" + moduleName + ".coffee" },
// Returns a transform stream.
function () { return coffee(); }
)
) amdOptimize.src(moduleName, options)Same as AlgorithmsResolving pathsFinding files
Recommended modules
var concat = require("gulp-concat");
gulp.src("src/scripts/**/*.js")
.pipe(amdOptimize("index"))
.pipe(concat("index.js"))
.pipe(gulp.dest("dist"));
var uglify = require("gulp-uglify");
gulp.src("src/scripts/**/*.js")
.pipe(amdOptimize("index"))
.pipe(concat("index.js"))
.pipe(uglify())
.pipe(gulp.dest("dist"));
var coffee = require("gulp-coffee");
gulp.src("src/scripts/**/*.coffee")
.pipe(coffee())
.pipe(amdOptimize("index"))
.pipe(concat("index.js"))
.pipe(gulp.dest("dist"));
var gif = require("gulp-if");
gulp.src("src/scripts/**/*.{coffee,js}")
.pipe(gif(function (file) { return path.extname(file) == ".coffee"; }, coffee()))
.pipe(amdOptimize("index"))
.pipe(concat("index.js"))
.pipe(gulp.dest("dist"));
var eventStream = require("event-stream");
var order = require("gulp-order");
eventStream.merge(
gulp.src("bower_components/almond/almond.js"),
gulp.src(amdOptimize("index"))
.pipe(concat("index.js"))
)
.pipe(order(["**/almond.js", "**/index.js"]))
.pipe(concat("index.js"))
.pipe(gulp.dest("dist")); Current limitations
Tests
LicenseMIT © scalable minds 2014 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论