Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed full lodash library import #786

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
var vm = require('vm');
var fs = require('fs');
var _ = require('lodash');
var _extend = require('lodash/extend');
var _uniq = require('lodash/uniq');
var Promise = require('bluebird');
var path = require('path');
var childCompiler = require('./lib/compiler.js');
Expand All @@ -11,7 +12,7 @@ Promise.promisifyAll(fs);

function HtmlWebpackPlugin (options) {
// Default options
this.options = _.extend({
this.options = _extend({
template: path.join(__dirname, 'default_index.ejs'),
filename: 'index.html',
hash: false,
Expand Down Expand Up @@ -153,7 +154,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
// Add the stylesheets, scripts and so on to the resulting html
return self.postProcessHtml(html, assets, { body: result.body, head: result.head })
.then(function (html) {
return _.extend(result, {html: html, assets: assets});
return _extend(result, {html: html, assets: assets});
});
});
})
Expand Down Expand Up @@ -223,7 +224,7 @@ HtmlWebpackPlugin.prototype.evaluateCompilationResult = function (compilation, s
// To extract the result during the evaluation this part has to be removed.
source = source.replace('var HTML_WEBPACK_PLUGIN_RESULT =', '');
var template = this.options.template.replace(/^.+!/, '').replace(/\?.+$/, '');
var vmContext = vm.createContext(_.extend({HTML_WEBPACK_PLUGIN: true, require: require}, global));
var vmContext = vm.createContext(_extend({HTML_WEBPACK_PLUGIN: true, require: require}, global));
var vmScript = new vm.Script(source, {filename: template});
// Evaluate code and cast to string
var newSource;
Expand Down Expand Up @@ -461,7 +462,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu

// Duplicate css assets can occur on occasion if more than one chunk
// requires the same css.
assets.css = _.uniq(assets.css);
assets.css = _uniq(assets.css);

return assets;
};
Expand Down Expand Up @@ -626,7 +627,7 @@ HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) {
* asset object
*/
HtmlWebpackPlugin.prototype.getAssetFiles = function (assets) {
var files = _.uniq(Object.keys(assets).filter(function (assetType) {
var files = _uniq(Object.keys(assets).filter(function (assetType) {
return assetType !== 'chunks' && assets[assetType];
}).reduce(function (files, assetType) {
return files.concat(assets[assetType]);
Expand All @@ -647,7 +648,7 @@ HtmlWebpackPlugin.prototype.applyPluginsAsyncWaterfall = function (compilation)
if (requiresResult && !result) {
compilation.warnings.push(new Error('Using ' + eventName + ' without returning a result is deprecated.'));
}
return _.extend(pluginArgs, result);
return _extend(pluginArgs, result);
});
};
};
Expand Down
4 changes: 2 additions & 2 deletions lib/chunksorter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var toposort = require('toposort');
var _ = require('lodash');
var _isObject = require('lodash/isObject');

/*
Sorts dependencies between chunks by their "parents" attribute.
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports.dependency = function (chunks) {
// Add an edge for each parent (parent -> child)
chunk.parents.forEach(function (parentId) {
// webpack2 chunk.parents are chunks instead of string id(s)
var parentChunk = _.isObject(parentId) ? parentId : nodeMap[parentId];
var parentChunk = _isObject(parentId) ? parentId : nodeMap[parentId];
// If the parent chunk does not exist (e.g. because of an excluded chunk)
// we ignore that parent
if (parentChunk) {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
'use strict';
var Promise = require('bluebird');
var _ = require('lodash');
var _assign = require('lodash/assign');
var path = require('path');
var NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
var NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
Expand Down Expand Up @@ -38,7 +38,7 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
publicPath: compilation.outputOptions.publicPath
};
// Store the result of the parent compilation before we start the child compilation
var assetsBeforeCompilation = _.assign({}, compilation.assets[outputOptions.filename]);
var assetsBeforeCompilation = _assign({}, compilation.assets[outputOptions.filename]);
// Create an additional child compiler which takes the template
// and turns it into an Node.JS html factory.
// This allows us to use loaders during the compilation
Expand Down
5 changes: 3 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* This loader renders the template with underscore if no other loader was found */
'use strict';

var _ = require('lodash');
var _template = require('lodash/template');
var _defaults = require('lodash/defaults');
var loaderUtils = require('loader-utils');

module.exports = function (source) {
Expand Down Expand Up @@ -29,7 +30,7 @@ module.exports = function (source) {
// the parameters passed to the compiled template inside the scope. We therefore
// need to unwrap them ourselves here. This is essentially what lodash does internally
// To tell lodash it should not use with we set a variable
var template = _.template(source, _.defaults(options, { variable: 'data' }));
var template = _template(source, _defaults(options, { variable: 'data' }));
// All templateVariables which should be available
// @see HtmlWebpackPlugin.prototype.executeTemplate
var templateVariables = [
Expand Down
8 changes: 4 additions & 4 deletions spec/BasicSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var rimraf = require('rimraf');
var _ = require('lodash');
var _extend = require('lodash/extend');
var CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractTextPluginMajorVersion = require('extract-text-webpack-plugin/package.json').version.split('.')[0];
Expand Down Expand Up @@ -1026,7 +1026,7 @@ describe('HtmlWebpackPlugin', function () {
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-html-processing', function (object, callback) {
eventFiredForFirstPlugin = true;
var result = _.extend(object, {
var result = _extend(object, {
html: object.html + 'Injected by first plugin'
});
callback(null, result);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ describe('HtmlWebpackPlugin', function () {
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-html-processing', function (object, callback) {
eventFiredForFirstPlugin = true;
var result = _.extend(object, {
var result = _extend(object, {
html: object.html + 'Injected by first plugin'
});
callback(null, result);
Expand All @@ -1087,7 +1087,7 @@ describe('HtmlWebpackPlugin', function () {
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-html-processing', function (object, callback) {
eventFiredForSecondPlugin = true;
var result = _.extend(object, {
var result = _extend(object, {
html: object.html + ' Injected by second plugin'
});
callback(null, result);
Expand Down