Reduce production built size
This commit is contained in:
parent
a96fa1622b
commit
f4d1cb7e1e
13 changed files with 56 additions and 38 deletions
2
.babelrc
2
.babelrc
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"presets": [
|
"presets": [
|
||||||
"env", "react"
|
["env", { modules: false }], "react"
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"transform-class-properties"
|
"transform-class-properties"
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-preset-env": "^1.6.0",
|
"babel-preset-env": "^1.6.0",
|
||||||
"leaflet": "^1.3.1",
|
"leaflet": "^1.3.1",
|
||||||
"lodash": "^4.17.4",
|
"lodash-es": "^4.17.4",
|
||||||
"material-ui": "npm:material-ui@next",
|
"material-ui": "npm:material-ui@next",
|
||||||
"material-ui-old": "npm:material-ui@latest",
|
"material-ui-old": "npm:material-ui@latest",
|
||||||
"mdi": "^2.0.46",
|
"mdi": "^2.0.46",
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
"flow-typed": "^2.3.0",
|
"flow-typed": "^2.3.0",
|
||||||
"html-webpack-plugin": "^2.30.1",
|
"html-webpack-plugin": "^2.30.1",
|
||||||
"husky": "^0.14.3",
|
"husky": "^0.14.3",
|
||||||
|
"lodash-webpack-plugin": "^0.11.4",
|
||||||
"style-loader": "^0.20.1",
|
"style-loader": "^0.20.1",
|
||||||
"webpack": "^3.1.0",
|
"webpack": "^3.1.0",
|
||||||
"webpack-dev-server": "^2.11.1",
|
"webpack-dev-server": "^2.11.1",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import _ from "lodash";
|
import map from "lodash/map";
|
||||||
|
import mapValues from "lodash/mapValues";
|
||||||
|
import filter from "lodash/filter";
|
||||||
|
import keys from "lodash/keys";
|
||||||
|
import merge from "lodash/merge";
|
||||||
|
|
||||||
import type { Config, Control, Topics } from "config/types";
|
import type { Config, Control, Topics } from "config/types";
|
||||||
|
|
||||||
|
|
@ -37,7 +41,7 @@ class App extends React.Component<AppProps & Classes, AppState> {
|
||||||
this.state = {
|
this.state = {
|
||||||
selectedControl: null,
|
selectedControl: null,
|
||||||
drawerOpened: false,
|
drawerOpened: false,
|
||||||
mqttState: _.mapValues(this.topics, (topic) => ({
|
mqttState: mapValues(this.topics, (topic) => ({
|
||||||
actual: topic.defaultValue,
|
actual: topic.defaultValue,
|
||||||
internal: keyOf(topic.values, topic.defaultValue)
|
internal: keyOf(topic.values, topic.defaultValue)
|
||||||
})),
|
})),
|
||||||
|
|
@ -46,7 +50,7 @@ class App extends React.Component<AppProps & Classes, AppState> {
|
||||||
onConnect: () => this.setState({ mqttConnected: true }),
|
onConnect: () => this.setState({ mqttConnected: true }),
|
||||||
onReconnect: () => this.setState({ mqttConnected: false }),
|
onReconnect: () => this.setState({ mqttConnected: false }),
|
||||||
onDisconnect: () => this.setState({ mqttConnected: false }),
|
onDisconnect: () => this.setState({ mqttConnected: false }),
|
||||||
subscribe: _.map(this.topics, (x) => x.state)
|
subscribe: map(this.topics, (x) => x.state)
|
||||||
}),
|
}),
|
||||||
mqttConnected: false
|
mqttConnected: false
|
||||||
};
|
};
|
||||||
|
|
@ -74,8 +78,8 @@ class App extends React.Component<AppProps & Classes, AppState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
receiveMessage(rawTopic: string, message: Object) {
|
receiveMessage(rawTopic: string, message: Object) {
|
||||||
const topics = _.filter(
|
const topics = filter(
|
||||||
_.keys(this.topics),
|
keys(this.topics),
|
||||||
(k) => this.topics[k].state === rawTopic
|
(k) => this.topics[k].state === rawTopic
|
||||||
);
|
);
|
||||||
if (topics.length === 0) {
|
if (topics.length === 0) {
|
||||||
|
|
@ -85,7 +89,7 @@ class App extends React.Component<AppProps & Classes, AppState> {
|
||||||
const topic = topics[i];
|
const topic = topics[i];
|
||||||
const parseValue = this.topics[topic].parseState;
|
const parseValue = this.topics[topic].parseState;
|
||||||
const val = parseValue == null ? message.toString() : parseValue(message);
|
const val = parseValue == null ? message.toString() : parseValue(message);
|
||||||
this.setState({mqttState: _.merge(this.state.mqttState,
|
this.setState({mqttState: merge(this.state.mqttState,
|
||||||
{ [topic]: {
|
{ [topic]: {
|
||||||
actual: val,
|
actual: val,
|
||||||
internal: keyOf(this.topics[topic].values, val) || val
|
internal: keyOf(this.topics[topic].values, val) || val
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Map, ImageOverlay, Marker, LayersControl } from "react-leaflet";
|
import { Map, ImageOverlay, Marker, LayersControl } from "react-leaflet";
|
||||||
import Leaflet from "leaflet";
|
import { CRS, point, divIcon } from "leaflet";
|
||||||
import _ from "lodash";
|
import map from "lodash/map";
|
||||||
|
import mapValues from "lodash/mapValues";
|
||||||
import parseIconName, { controlGetIcon } from "utils/parseIconName";
|
import parseIconName, { controlGetIcon } from "utils/parseIconName";
|
||||||
|
|
||||||
import type { Controls, Control } from "config/types";
|
import type { Controls, Control } from "config/types";
|
||||||
|
|
@ -37,7 +38,7 @@ export default class ControlMap extends React.Component<ControlMapProps> {
|
||||||
return (
|
return (
|
||||||
<Map center={this.center}
|
<Map center={this.center}
|
||||||
zoom={this.props.zoom}
|
zoom={this.props.zoom}
|
||||||
crs={Leaflet.CRS.Simple}>
|
crs={CRS.Simple}>
|
||||||
{this.renderMarkers()}
|
{this.renderMarkers()}
|
||||||
{this.renderLayers()}
|
{this.renderLayers()}
|
||||||
</Map>
|
</Map>
|
||||||
|
|
@ -45,23 +46,23 @@ export default class ControlMap extends React.Component<ControlMapProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderMarkers() {
|
renderMarkers() {
|
||||||
return _.map(this.props.controls, this.renderMarker.bind(this));
|
return map(this.props.controls, this.renderMarker.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
createLeafletIcon(control: Control) {
|
createLeafletIcon(control: Control) {
|
||||||
const icon = controlGetIcon(control, this.props.state);
|
const icon = controlGetIcon(control, this.props.state);
|
||||||
const iconClass = parseIconName(`${icon} 36px`);
|
const iconClass = parseIconName(`${icon} 36px`);
|
||||||
return Leaflet.divIcon({
|
return divIcon({
|
||||||
iconSize: Leaflet.point(36, 36),
|
iconSize: point(36, 36),
|
||||||
iconAnchor: Leaflet.point(18, 18),
|
iconAnchor: point(18, 18),
|
||||||
html: `<i class="${iconClass}"
|
html: `<i class="${iconClass}"
|
||||||
style="line-height: 1; color: ${this.iconColor(control)}"></i>`
|
style="line-height: 1; color: ${this.iconColor(control)}"></i>`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
iconColor(control: Control): string {
|
iconColor(control: Control): string {
|
||||||
const ints = _.mapValues(this.props.state, (x) => x.internal || x.actual);
|
const ints = mapValues(this.props.state, (x) => x.internal || x.actual);
|
||||||
const acts = _.mapValues(this.props.state, (x) => x.actual);
|
const acts = mapValues(this.props.state, (x) => x.actual);
|
||||||
if (control.iconColor != null) {
|
if (control.iconColor != null) {
|
||||||
return control.iconColor(ints, acts, this.props.state);
|
return control.iconColor(ints, acts, this.props.state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import _ from "lodash";
|
import keys from "lodash/keys";
|
||||||
|
import map from "lodash/map";
|
||||||
import {
|
import {
|
||||||
ListItemSecondaryAction,
|
ListItemSecondaryAction,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
|
|
@ -142,11 +143,11 @@ export class DropDown extends UiControl<UIDropDown> {
|
||||||
runPrimaryAction = (next?: Actual) => {
|
runPrimaryAction = (next?: Actual) => {
|
||||||
if (this.isEnabled()) {
|
if (this.isEnabled()) {
|
||||||
const control = this.props.item;
|
const control = this.props.item;
|
||||||
const keys = _.keys(control.options);
|
const optionKeys = keys(control.options);
|
||||||
const value = this.getValue();
|
const value = this.getValue();
|
||||||
const valueIndex = keyOf(keys, value);
|
const valueIndex = keyOf(optionKeys, value);
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
this.changeState(keys[(valueIndex + 1) % keys.length]);
|
this.changeState(optionKeys[(valueIndex + 1) % optionKeys.length]);
|
||||||
} else {
|
} else {
|
||||||
this.changeState(next);
|
this.changeState(next);
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +172,7 @@ export class DropDown extends UiControl<UIDropDown> {
|
||||||
disabled={!this.isEnabled()}
|
disabled={!this.isEnabled()}
|
||||||
input={<Input id={id} />}
|
input={<Input id={id} />}
|
||||||
>
|
>
|
||||||
{_.map(options, (v, k) => <MenuItem value={k} key={k}>{v}</MenuItem>)}
|
{map(options, (v, k) => <MenuItem value={k} key={k}>{v}</MenuItem>)}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import _ from "lodash";
|
|
||||||
import {
|
import {
|
||||||
ListItem,
|
ListItem,
|
||||||
ListItemIcon,
|
ListItemIcon,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import mqtt from "mqtt";
|
import mqtt from "mqtt";
|
||||||
import _ from "lodash";
|
import uniq from "lodash/uniq";
|
||||||
|
|
||||||
// TODO: type mqtt.js
|
// TODO: type mqtt.js
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ export default function connectMqtt(
|
||||||
const client = mqtt.connect(url);
|
const client = mqtt.connect(url);
|
||||||
client.on("connect", () => {
|
client.on("connect", () => {
|
||||||
if (settings.subscribe != null) {
|
if (settings.subscribe != null) {
|
||||||
client.subscribe(_.uniq(settings.subscribe));
|
client.subscribe(uniq(settings.subscribe));
|
||||||
}
|
}
|
||||||
if (settings.onConnect != null) {
|
if (settings.onConnect != null) {
|
||||||
settings.onConnect(client);
|
settings.onConnect(client);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
import _ from "lodash";
|
import findKey from "lodash/findKey";
|
||||||
|
|
||||||
const keyOf = <a, b> (map: Map<a, b>, value: b): ?a => (
|
const keyOf = <a, b> (map: Map<a, b>, value: b): ?a => (
|
||||||
_.findKey(map, (x) => x === value)
|
findKey(map, (x) => x === value)
|
||||||
);
|
);
|
||||||
|
|
||||||
export default keyOf;
|
export default keyOf;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import _ from "lodash";
|
|
||||||
import { getInternals, getActuals } from "utils/state";
|
import { getInternals, getActuals } from "utils/state";
|
||||||
|
|
||||||
import type { Control } from "config/types";
|
import type { Control } from "config/types";
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
import _ from "lodash";
|
import mapValues from "lodash/mapValues";
|
||||||
|
|
||||||
export const getInternals = (state: State): Map<string, Internal> =>
|
export const getInternals = (state: State): Map<string, Internal> =>
|
||||||
_.mapValues(state, (x) => x.internal || x.actual);
|
mapValues(state, (x) => x.internal || x.actual);
|
||||||
|
|
||||||
export const getActuals = (state: State): Map<string, Actual> =>
|
export const getActuals = (state: State): Map<string, Actual> =>
|
||||||
_.mapValues(state, (x) => x.actual);
|
mapValues(state, (x) => x.actual);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ const preBuildScripts = process.env.NO_FLOW == undefined ?
|
||||||
module.exports = {
|
module.exports = {
|
||||||
resolve: {
|
resolve: {
|
||||||
modules: [path.resolve(__dirname, "src"), "node_modules"],
|
modules: [path.resolve(__dirname, "src"), "node_modules"],
|
||||||
extensions: ['.js', '.jsx']
|
extensions: ['.js', '.jsx'],
|
||||||
|
alias: {
|
||||||
|
'lodash': 'lodash-es'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, 'dist'),
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
|
@ -30,6 +33,6 @@ module.exports = {
|
||||||
title: 'Space Map',
|
title: 'Space Map',
|
||||||
template: 'index.ejs'
|
template: 'index.ejs'
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("styles.css")
|
new ExtractTextPlugin("styles.css"),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ const path = require('path');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const common = require('./webpack.common.js');
|
const common = require('./webpack.common.js');
|
||||||
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||||
|
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
|
||||||
|
|
||||||
const extractCSS = ExtractTextPlugin.extract({
|
const extractCSS = ExtractTextPlugin.extract({
|
||||||
fallback: "style-loader",
|
fallback: "style-loader",
|
||||||
|
|
@ -26,7 +27,6 @@ module.exports = env => merge(common, {
|
||||||
entry: {
|
entry: {
|
||||||
main: [configPath(env),
|
main: [configPath(env),
|
||||||
path.resolve(__dirname, 'src/index.jsx')],
|
path.resolve(__dirname, 'src/index.jsx')],
|
||||||
vendor: ['react', 'material-ui', 'mqtt', 'lodash']
|
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
|
|
@ -36,16 +36,16 @@ module.exports = env => merge(common, {
|
||||||
},
|
},
|
||||||
devtool: "source-map",
|
devtool: "source-map",
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.UglifyJsPlugin(),
|
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
'NODE_ENV': JSON.stringify('production')
|
'NODE_ENV': JSON.stringify('production')
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
new LodashModuleReplacementPlugin(),
|
||||||
|
new webpack.optimize.UglifyJsPlugin(),
|
||||||
|
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||||
new webpack.HashedModuleIdsPlugin(),
|
new webpack.HashedModuleIdsPlugin(),
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.AggressiveMergingPlugin(),
|
||||||
name: 'vendor'
|
|
||||||
}),
|
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
name: 'runtime'
|
name: 'runtime'
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
10
yarn.lock
10
yarn.lock
|
|
@ -3781,6 +3781,16 @@ lodash-es@^4.0.0, lodash-es@^4.2.1:
|
||||||
version "4.17.4"
|
version "4.17.4"
|
||||||
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7"
|
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7"
|
||||||
|
|
||||||
|
lodash-es@^4.17.4:
|
||||||
|
version "4.17.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.5.tgz#9fc6e737b1c4d151d8f9cae2247305d552ce748f"
|
||||||
|
|
||||||
|
lodash-webpack-plugin@^0.11.4:
|
||||||
|
version "0.11.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash-webpack-plugin/-/lodash-webpack-plugin-0.11.4.tgz#6c3ecba3d4b8d24b53940b63542715c5ed3c4ac5"
|
||||||
|
dependencies:
|
||||||
|
lodash "^4.17.4"
|
||||||
|
|
||||||
lodash.assign@^4.0.3, lodash.assign@^4.0.6:
|
lodash.assign@^4.0.3, lodash.assign@^4.0.6:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"
|
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue