Skip to content

Commit d959982

Browse files
authored
Merge pull request #81 from mjmiguel/bundle-opt
Bundle optimization
2 parents 666b744 + dd194b0 commit d959982

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"plugins": [
1313
["@babel/transform-runtime"],
1414
["@babel/proposal-class-properties"],
15-
["@babel/proposal-object-rest-spread"]
15+
["@babel/proposal-object-rest-spread"],
16+
["@babel/plugin-syntax-dynamic-import"]
1617
]
1718
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,13 @@
278278
"@babel/core": "^7.10.3",
279279
"@babel/plugin-proposal-class-properties": "^7.10.4",
280280
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
281+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
281282
"@babel/plugin-transform-runtime": "^7.10.3",
282283
"@babel/preset-env": "^7.10.3",
283284
"@babel/preset-react": "^7.10.1",
284285
"@babel/preset-typescript": "^7.10.4",
285286
"@jest-runner/electron": "^3.0.0",
287+
"@loadable/component": "^5.13.1",
286288
"@testing-library/jest-dom": "^5.11.0",
287289
"@testing-library/react": "^10.4.3",
288290
"@types/cookie": "^0.4.0",
@@ -341,6 +343,7 @@
341343
"typescript": "^3.9.6",
342344
"url-loader": "^4.1.0",
343345
"webpack": "^4.43.0",
346+
"webpack-bundle-analyzer": "^3.8.0",
344347
"webpack-cli": "^3.3.12",
345348
"webpack-dev-server": "^3.11.0",
346349
"webpack-node-externals": "^1.7.2"

src/client/components/composer/NewRequest/ComposerNewRequest.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import React from "react";
22
import uuid from "uuid/v4"; // (Universally Unique Identifier)--generates a unique ID
33
import gql from "graphql-tag";
4+
import loadable from "@loadable/component";
5+
46
import HeaderEntryForm from "./HeaderEntryForm.jsx";
57
import BodyEntryForm from "./BodyEntryForm.jsx";
6-
import GraphQLBodyEntryForm from "./GraphQLBodyEntryForm.jsx";
78
import GRPCProtoEntryForm from "./GRPCProtoEntryForm.jsx";
89
import FieldEntryForm from "./FieldEntryForm.jsx";
910
import CookieEntryForm from "./CookieEntryForm.jsx";
1011
import historyController from "../../../controllers/historyController";
1112
import GraphQLIntrospectionLog from "./GraphQLIntrospectionLog";
12-
import GraphQLVariableEntryForm from "./GraphQLVariableEntryForm";
13+
14+
// lazy loading to reduce bundle size (codemirror)
15+
const GraphQLBodyEntryForm = loadable(() => import('./GraphQLBodyEntryForm'));
16+
const GraphQLVariableEntryForm = loadable(() => import('./GraphQLVariableEntryForm'));
17+
1318

1419
const ComposerNewRequest = ({
1520
setNewRequestFields,

src/client/components/containers/ContentsContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as React from "react";
2+
import loadable from "@loadable/component";
3+
4+
// lazy loading to reduce bundle size (chart.js)
5+
const BarGraph = loadable(() => import('../display/BarGraph'))
26

3-
import BarGraph from "../display/BarGraph";
47
import ReqResContainer from "./ReqResContainer.jsx";
58
import NavBarContainer from "./NavBarContainer.jsx";
69

src/client/db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Dexie from "dexie";
2-
1+
import Dexie from 'dexie'
2+
33
const db = new Dexie("Swell");
44

55
db.on("versionchange", function (event) {

webpack.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const path = require("path");
22
const HtmlWebpackPlugin = require("html-webpack-plugin");
33
const CspHtmlWebpackPlugin = require("csp-html-webpack-plugin");
44
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5-
const nodeExternals = require("webpack-node-externals");
5+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
6+
67

78
module.exports = {
89
target: "web",
@@ -79,5 +80,11 @@ module.exports = {
7980
},
8081
}),
8182
new CspHtmlWebpackPlugin(),
83+
// options here: https://github.com/webpack-contrib/webpack-bundle-analyzer
84+
// set to true to display bundle breakdown
85+
new BundleAnalyzerPlugin({
86+
openAnalyzer: true,
87+
analyzerMode: 'static'
88+
}),
8289
],
8390
};

0 commit comments

Comments
 (0)