lodash-webpack-plugin
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -27,4 +27,7 @@ 'use strict'; | ||
var reLodash = RegExp('/lodash(?:/(?!fp/)|-es/|-amd/)'); | ||
var reLodashPath = RegExp('/lodash(?:/(?!fp/)|-es/|-amd/)'); | ||
var reLodashRaw = RegExp('^lodash(?:/|-es/|-amd/)\\w+$'); | ||
var stubs = ['./identity.js', './noop.js', './stubArray.js', './stubFalse.js', './stubObject.js', './stubString.js', './stubTrue.js']; | ||
var LodashModuleReplacementPlugin = function () { | ||
@@ -54,4 +57,7 @@ function LodashModuleReplacementPlugin(options) { | ||
var resolvePath = _lodash2.default.memoize(function (resource) { | ||
if (reLodash.test(resource)) { | ||
var resolvePath = _lodash2.default.memoize(function (data) { | ||
var rawRequest = data.rawRequest; | ||
var resource = data.resource; | ||
if (reLodashPath.test(resource)) { | ||
var length = _this2.patterns.length; | ||
@@ -61,3 +67,5 @@ | ||
var pair = _this2.patterns[length]; | ||
if (_lodash2.default.endsWith(resource, pair[0])) { | ||
// Replace the resource if it end swith the first pattern of the pair as | ||
// long as it isn't an explicit request for a module which is to be stubbed. | ||
if (_lodash2.default.endsWith(resource, pair[0]) && !(reLodashRaw.test(rawRequest) && _lodash2.default.includes(stubs, pair[1]))) { | ||
var result = _path2.default.resolve(_path2.default.dirname(resource), pair[1]); | ||
@@ -72,11 +80,13 @@ if (_fs2.default.existsSync(result)) { | ||
return resource; | ||
}, function (data) { | ||
return data.resource; | ||
}); | ||
compiler.plugin('normal-module-factory', function (nmf) { | ||
nmf.plugin('after-resolve', function (result, callback) { | ||
if (!result) { | ||
nmf.plugin('after-resolve', function (data, callback) { | ||
if (!data) { | ||
return callback(); | ||
} | ||
result.resource = resolvePath(result.resource); | ||
return callback(null, result); | ||
data.resource = resolvePath(data); | ||
return callback(null, data); | ||
}); | ||
@@ -83,0 +93,0 @@ }); |
@@ -8,12 +8,12 @@ 'use strict'; | ||
'caching': [['_createSet', 'noop'], ['_MapCache', '_ListCache'], ['_Stack', '_ListCache']], | ||
'chaining': [['_getFuncName', 'noop'], ['_isLaziable', 'noop'], ['_LodashWrapper', 'noop']], | ||
'chaining': [['_getFuncName', 'stubString'], ['_getFuncName', 'noop'], ['_isLaziable', 'stubFalse'], ['_isLaziable', 'noop'], ['_LodashWrapper', 'noop']], | ||
'coercions': [['_baseToNumber', 'identity'], ['_baseToString', 'identity'], ['_toKey', 'identity'], ['toFinite', 'identity'], ['toInteger', 'identity'], ['toLength', 'identity'], ['toNumber', 'identity'], ['toString', 'identity']], | ||
'collections': [['_baseAggregator', '_arrayAggregator'], ['each', '_arrayEach'], ['eachRight', '_arrayEachRight'], ['every', '_arrayEvery'], ['filter', '_arrayFilter'], ['forEach', '_arrayEach'], ['forEachRight', '_arrayEachRight'], ['includes', '_arrayIncludes'], ['map', '_arrayMap'], ['reduce', '_arrayReduce'], ['reduceRight', '_arrayReduceRight'], ['some', '_arraySome']], | ||
'collections': [['_baseAggregator', '_arrayAggregator'], ['_baseFilter', '_arrayFilter'], ['_baseMap', '_arrayMap'], ['each', '_arrayEach'], ['eachRight', '_arrayEachRight'], ['every', '_arrayEvery'], ['filter', '_arrayFilter'], ['forEach', '_arrayEach'], ['forEachRight', '_arrayEachRight'], ['includes', '_arrayIncludes'], ['map', '_arrayMap'], ['reduce', '_arrayReduce'], ['reduceRight', '_arrayReduceRight'], ['some', '_arraySome']], | ||
'currying': [['_createWrapper', '_createPartialWrapper']], | ||
'flattening': [['_baseFlatten', 'identity']], | ||
'guards': [['_isHostObject', 'noop'], ['_isIterateeCall', 'noop'], ['_isPrototype', 'noop'], ['isArguments', 'noop'], ['isNative', 'identity'], ['keys', '_baseKeys']], | ||
'guards': [['_getNative', '_getValue'], ['_isHostObject', 'stubFalse'], ['_isHostObject', 'noop'], ['_isIterateeCall', 'stubFalse'], ['_isIterateeCall', 'noop'], ['_isPrototype', 'stubFalse'], ['_isPrototype', 'noop'], ['isArguments', 'stubFalse'], ['isArguments', 'noop'], ['isNative', 'stubTrue'], ['isNative', 'identity'], ['keys', '_baseKeys'], ['times', '_baseTimes']], | ||
'memoizing': [['memoize', 'identity']], | ||
'metadata': [['_baseSetData', 'identity'], ['_getData', 'noop'], ['_mergeData', 'identity'], ['_setData', 'identity']], | ||
'paths': [['_castPath', 'identity'], ['_isKey', 'identity']], | ||
'placeholders': [['_composeArgs', 'identity'], ['_composeArgsRight', 'identity'], ['_getHolder', 'noop'], ['_getPlaceholder', 'noop'], ['_replaceHolders', 'constant']], | ||
'placeholders': [['_composeArgs', 'identity'], ['_composeArgsRight', 'identity'], ['_getHolder', 'noop'], ['_getPlaceholder', 'noop'], ['_replaceHolders', 'stubArray'], ['_replaceHolders', 'constant']], | ||
'shorthands': [['_baseIteratee', 'identity']] | ||
@@ -20,0 +20,0 @@ }; |
{ | ||
"name": "lodash-webpack-plugin", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Smaller modular Lodash builds.", | ||
@@ -17,2 +17,3 @@ "keywords": "webpack-plugin, lodash, modules", | ||
"build": "babel src --out-dir lib", | ||
"prepublish": "npm run build", | ||
"test": "mocha --check-leaks --slow 1e3 --compilers js:babel-core/register" | ||
@@ -27,4 +28,4 @@ }, | ||
"babel-loader": "^6.2.4", | ||
"babel-plugin-add-module-exports": "~0.2.0", | ||
"babel-plugin-lodash": "^3.1.2", | ||
"babel-plugin-add-module-exports": "~0.2.1", | ||
"babel-plugin-lodash": "^3.1.3", | ||
"babel-preset-es2015": "^6.6.0", | ||
@@ -31,0 +32,0 @@ "bluebird": "^3.3.5", |
@@ -1,2 +0,2 @@ | ||
# lodash-webpack-plugin v0.3.0 | ||
# lodash-webpack-plugin v0.4.0 | ||
@@ -3,0 +3,0 @@ Create smaller Lodash builds by replacing [feature sets](#feature-sets) of modules |
11293
94