build(webpack): bundle size optimization for lodash (#6244)

* add duplicate code detection check for general purpose use
* webpack alias for lodash
* redux and react-redux dependency bump that removes lodash dependencies
* lodash version match with swagger-client and recent security update
* additional webpack config to help reduce build sizes
* restore max bundle size back to 1024000
This commit is contained in:
Tim Lai
2020-07-20 20:26:56 -07:00
committed by GitHub
parent cb16ba4e6a
commit d12662e354
6 changed files with 382 additions and 36 deletions

View File

@@ -118,8 +118,9 @@ export default function buildConfig(
// these aliases make sure that we don't bundle same libraries twice
// when the versions of these libraries diverge between swagger-js and swagger-ui
alias: {
"@babel/runtime-corejs2": path.resolve(__dirname, '..', 'node_modules/@babel/runtime-corejs2'),
"js-yaml": path.resolve(__dirname, '..', 'node_modules/js-yaml')
"@babel/runtime-corejs2": path.resolve(__dirname, "..", "node_modules/@babel/runtime-corejs2"),
"js-yaml": path.resolve(__dirname, "..", "node_modules/js-yaml"),
"lodash": path.resolve(__dirname, "..", "node_modules/lodash")
},
},
@@ -133,8 +134,8 @@ export default function buildConfig(
performance: {
hints: "error",
maxEntrypointSize: 1073152, // 1048 KiB,
maxAssetSize: 1073152,
maxEntrypointSize: 1024000,
maxAssetSize: 1024000,
},
optimization: {

View File

@@ -2,9 +2,10 @@
* @prettier
*/
import path from "path"
import configBuilder from "./_config-builder"
import { DuplicatesPlugin } from "inspectpack/plugin"
import LodashModuleReplacementPlugin from "lodash-webpack-plugin"
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
const result = configBuilder(
{
@@ -20,10 +21,19 @@ const result = configBuilder(
"./src/core/index.js",
],
},
output: {
library: "SwaggerUIBundle",
},
plugins: [
new DuplicatesPlugin({
// emit compilation warning or error? (Default: `false`)
emitErrors: false,
// display full duplicates information? (Default: `false`)
verbose: false,
}),
new LodashModuleReplacementPlugin(),
new WebpackBundleSizeAnalyzerPlugin("log.bundle-sizes.swagger-ui.txt"),
]
}
)