mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add "iife=.." command to build.js.
Former-commit-id: 85d8c7ea550403663a878f2713ce93ae8c2dbc6a
This commit is contained in:
34
build.js
34
build.js
@@ -285,10 +285,14 @@
|
|||||||
' lodash mobile Build with IE < 9 bug fixes & method compilation removed',
|
' lodash mobile Build with IE < 9 bug fixes & method compilation removed',
|
||||||
' lodash strict Build with `_.bindAll`, `_.defaults`, & `_.extend` in strict mode',
|
' lodash strict Build with `_.bindAll`, `_.defaults`, & `_.extend` in strict mode',
|
||||||
' lodash underscore Build with only methods included in Underscore without iteration fixes',
|
' lodash underscore Build with only methods included in Underscore without iteration fixes',
|
||||||
' lodash category=... Comma separated categories of methods to include in the build',
|
|
||||||
' lodash exclude=... Comma separated names of methods to exclude from the build',
|
' lodash exclude=... Comma separated names of methods to exclude from the build',
|
||||||
' lodash exports=... Comma separated names of ways to export the `LoDash` function',
|
|
||||||
' lodash include=... Comma separated names of methods to include in the build',
|
' lodash include=... Comma separated names of methods to include in the build',
|
||||||
|
' lodash category=... Comma separated categories of methods to include in the build',
|
||||||
|
' (i.e. “arrays”, “chaining”, “collections”, “functions”, “objects”, and “utilities”)',
|
||||||
|
' lodash exports=... Comma separated names of ways to export the `LoDash` function',
|
||||||
|
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
|
||||||
|
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
|
||||||
|
' (e.g. “!function(window,undefined){%output%}(this)”)',
|
||||||
'',
|
'',
|
||||||
' All arguments, except `exclude` with `include` & `legacy` with `csp`/`mobile`,',
|
' All arguments, except `exclude` with `include` & `legacy` with `csp`/`mobile`,',
|
||||||
' may be combined.',
|
' may be combined.',
|
||||||
@@ -674,7 +678,7 @@
|
|||||||
// used to report invalid command-line arguments
|
// used to report invalid command-line arguments
|
||||||
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
||||||
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
||||||
/^(?:category|exclude|exports|include)=.*$/.test(value)) {
|
/^(?:category|exclude|exports|iife|include)=.*$/.test(value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
@@ -786,6 +790,11 @@
|
|||||||
return pair[1];
|
return pair[1];
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
|
// used to specify a custom IIFE to wrap Lo-Dash
|
||||||
|
var iife = options.reduce(function(result, value) {
|
||||||
|
return result || (result = value.match(/^iife=(.*)$/)) && result[1];
|
||||||
|
}, '');
|
||||||
|
|
||||||
// load customized Lo-Dash module
|
// load customized Lo-Dash module
|
||||||
var lodash = (function() {
|
var lodash = (function() {
|
||||||
var context = vm.createContext({
|
var context = vm.createContext({
|
||||||
@@ -1161,7 +1170,7 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// customize how the `LoDash` function is exported
|
// customize Lo-Dash's export bootstrap
|
||||||
if (exportsOptions.indexOf('amd') == -1) {
|
if (exportsOptions.indexOf('amd') == -1) {
|
||||||
source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1');
|
source = source.replace(/(?: *\/\/.*\n)*( +)if *\(typeof +define[\s\S]+?else /, '$1');
|
||||||
}
|
}
|
||||||
@@ -1180,6 +1189,21 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// customize Lo-Dash's IIFE
|
||||||
|
(function() {
|
||||||
|
if (iife) {
|
||||||
|
var token = '%output%',
|
||||||
|
index = iife.indexOf(token);
|
||||||
|
|
||||||
|
source = source.match(/\/\*![\s\S]+?\*\/\n/) +
|
||||||
|
iife.slice(0, index) +
|
||||||
|
source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') +
|
||||||
|
iife.slice(index + token.length);
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// modify/remove references to removed methods/variables
|
// modify/remove references to removed methods/variables
|
||||||
if (isRemoved(source, 'isArguments')) {
|
if (isRemoved(source, 'isArguments')) {
|
||||||
source = replaceVar(source, 'noArgsClass', 'false');
|
source = replaceVar(source, 'noArgsClass', 'false');
|
||||||
@@ -1269,7 +1293,7 @@
|
|||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// used to specify creating a custom build
|
// used to specify creating a custom build
|
||||||
var isCustom = !_.isEqual(exportsOptions, exportsAll) || filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore;
|
var isCustom = !_.isEqual(exportsOptions, exportsAll) || filterType || iife || isBackbone || isLegacy || isMobile || isStrict || isUnderscore;
|
||||||
|
|
||||||
// used to specify the output path for builds
|
// used to specify the output path for builds
|
||||||
var outputPath = options.reduce(function(result, value, index) {
|
var outputPath = options.reduce(function(result, value, index) {
|
||||||
|
|||||||
@@ -585,7 +585,8 @@
|
|||||||
'exports=amd',
|
'exports=amd',
|
||||||
'exports=commonjs',
|
'exports=commonjs',
|
||||||
'exports=global',
|
'exports=global',
|
||||||
'exports=node'
|
'exports=node',
|
||||||
|
'exports=none'
|
||||||
];
|
];
|
||||||
|
|
||||||
commands.forEach(function(command, index) {
|
commands.forEach(function(command, index) {
|
||||||
@@ -626,6 +627,11 @@
|
|||||||
vm.runInContext(source, context);
|
vm.runInContext(source, context);
|
||||||
ok(context._ === undefined, basename);
|
ok(context._ === undefined, basename);
|
||||||
ok(_.isFunction(context.module.exports), basename);
|
ok(_.isFunction(context.module.exports), basename);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
ok(context._ === undefined, basename);
|
||||||
}
|
}
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -635,6 +641,30 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('iife command');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
|
asyncTest('`lodash iife=...`', function() {
|
||||||
|
build(['-s', 'iife=!function(window,undefined){%output%}(this)'], function(source, filepath) {
|
||||||
|
var basename = path.basename(filepath, '.js'),
|
||||||
|
context = createContext();
|
||||||
|
|
||||||
|
try {
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
var lodash = context._ || {};
|
||||||
|
ok(_.isString(lodash.VERSION), basename);
|
||||||
|
ok(/!function/.test(source), basename);
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('output options');
|
QUnit.module('output options');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -676,7 +706,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
|
|
||||||
asyncTest('`minify underscore.js`', function() {
|
asyncTest('`node minify underscore.js`', function() {
|
||||||
var source = fs.readFileSync(path.join(__dirname, '..', 'vendor', 'underscore', 'underscore.js'), 'utf8');
|
var source = fs.readFileSync(path.join(__dirname, '..', 'vendor', 'underscore', 'underscore.js'), 'utf8');
|
||||||
minify(source, {
|
minify(source, {
|
||||||
'silent': true,
|
'silent': true,
|
||||||
|
|||||||
Reference in New Issue
Block a user