From 558036ee5351f13ef67c2013166e2d60f75fd180 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Mon, 12 Nov 2018 21:56:51 +0200 Subject: [PATCH] feat(webpack): reduce lodash size --- package.json | 3 ++- webpack/webpack.common.js | 8 +++++--- yarn.lock | 9 ++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cf325c4fc..1e98f5188 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dev": "yarn grunt run-dev", "clean-all": "yarn grunt clean:all", "dev:client": "webpack", - "build:client": "webpack --config ./webpack/webpack.production.js", + "build:client": "webpack -p --config ./webpack/webpack.production.js", "build-offline": "cd ./api/cmd/portainer && CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags '-s' && mv -b portainer ../../../dist/portainer-linux-amd64" }, "engines": { @@ -101,6 +101,7 @@ "html-loader": "^0.5.5", "html-webpack-plugin": "^3.2.0", "load-grunt-tasks": "^3.5.2", + "lodash-webpack-plugin": "^0.11.5", "mini-css-extract-plugin": "^0.4.4", "ngtemplate-loader": "^2.0.1", "style-loader": "^0.23.1", diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 98e2f78d3..0867af57f 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,11 +1,12 @@ const path = require('path'); -const { ProvidePlugin, ContextReplacementPlugin } = require('webpack'); +const { ProvidePlugin, IgnorePlugin } = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const WebpackBuildNotifierPlugin = require('webpack-build-notifier'); const CleanTerminalPlugin = require('clean-terminal-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); // const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +const LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); const npmPackage = require('../package.json'); const projectRoot = path.resolve(__dirname, '..'); @@ -92,7 +93,7 @@ module.exports = { new ProvidePlugin({ $: 'jquery', jQuery: 'jquery', - 'window.jQuery': 'jquery', + 'window.jQuery': 'jquery' }), new MiniCssExtractPlugin({ filename: '[name].css', @@ -100,8 +101,9 @@ module.exports = { sourceMap: true }), new CleanWebpackPlugin(['dist/public']), - new ContextReplacementPlugin(/moment[\/\\]locale$/, /en/) + new IgnorePlugin(/^\.\/locale$/, /moment$/), // new BundleAnalyzerPlugin() + new LodashModuleReplacementPlugin() ], optimization: { splitChunks: { diff --git a/yarn.lock b/yarn.lock index bd9ca6b86..eaefda5c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5396,6 +5396,13 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" +lodash-webpack-plugin@^0.11.5: + version "0.11.5" + resolved "https://registry.yarnpkg.com/lodash-webpack-plugin/-/lodash-webpack-plugin-0.11.5.tgz#c4bd064b4f561c3f823fa5982bdeb12c475390b9" + integrity sha512-QWfEIYxpixOdbd6KBe5g6MDWcyTgP3trDXwKHFqTlXrWiLcs/67fGQ0IWeRyhWlTITQIgMpJAYd2oeIztuV5VA== + dependencies: + lodash "^4.17.4" + lodash._basecopy@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" @@ -5591,7 +5598,7 @@ lodash@^4.17.10: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" integrity sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg== -lodash@^4.17.3, lodash@^4.17.5, lodash@~4.17.4: +lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@~4.17.4: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==