Skip to content

Commit e923498

Browse files
authored
improved bundling, webpack, babel (#7)
1 parent cb9f7ec commit e923498

10 files changed

Lines changed: 1192 additions & 779 deletions

File tree

.babelrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
2-
"presets": [["env", { "targets": { "chrome": 54, "safari": 10 } }], "stage-2", "react"],
2+
"presets": [
3+
["env", { "targets": { "chrome": 54, "safari": 10 }, "modules": false }],
4+
"stage-2",
5+
"react"
6+
],
37
"env": {
48
"production": {
59
"plugins": ["transform-react-remove-prop-types"]
10+
},
11+
"test": {
12+
"presets": [["env", { "targets": { "chrome": 54, "safari": 10 } }], "stage-2", "react"]
613
}
714
}
815
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ __snapshots__
1212
webpack/base.config.js
1313
webpack/dev.config.js
1414
webpack/prod.config.js
15+
webpack/prod.analyse.config.js

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1010

1111
* custom `<TrelloCardUi />` component added (replaces Trello's embedded iframe)
1212
* fallback for missing `avatarHash` implemented (use member's `initials`) added
13+
* `sideEffects` option for webpack's treeshaking feature added, `.babelrc` modified
14+
(`"modules": false`) and prod.config.js (webpack config) updated as well. Read more about
15+
treeshaking [here](https://webpack.js.org/guides/tree-shaking/),
16+
[here](https://stackoverflow.com/a/47675519/1238150) and
17+
[here](https://github.com/webpack/webpack/issues/6992#issuecomment-379662391).
1318

1419
### Changed
1520

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ proposals.
141141

142142
The following scripts are available (also work with `npm run`):
143143

144-
* `yarn run lint`: lints the js-code with Eslint (without `--fix`)
145-
* `yarn run lint:scss`: lints the scss-code with Stylelint (without `--fix`)
144+
* `yarn analyse`: bundles the production build and analyses it with [Jarvis][4], see other analyse [here][5].
145+
* `yarn lint`: lints the js-code with Eslint (without `--fix`)
146+
* `yarn lint:scss`: lints the scss-code with Stylelint (without `--fix`)
146147
* `yarn start`: starts the app with the webpack-dev-server
147148
* `yarn test`: runs tests with jest
148149
* `yarn test:watch`: runs tests with jest in watch mode
@@ -187,4 +188,6 @@ MIT
187188
[1]: https://trello.com/app-key
188189
[2]: http://localhost:2222/#/
189190
[3]: https://github.com/natterstefan/react-trello-multiboard/issues
191+
[4]: https://github.com/zouhir/jarvis
192+
[5]: https://survivejs.com/webpack/optimizing/build-analysis/
190193
[natterstefan]: https://github.com/natterstefan

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
"npm": ">=5.6.0",
1818
"yarn": ">=1.3.0"
1919
},
20+
"sideEffects": false,
2021
"scripts": {
22+
"analyse": "npm run build:clean-dist && cross-env NODE_ENV=production BABEL_ENV=production webpack -p --config webpack/prod.analyse.config.js",
23+
"analyse:size": "size-limit",
2124
"build": "npm run build:clean-dist && cross-env NODE_ENV=production BABEL_ENV=production webpack -p --config webpack/prod.config.js",
2225
"build:clean-dist": "rm -rf dist",
2326
"build:dev": "npm run build:clean-dist && webpack --config webpack/dev.config.js",
@@ -27,7 +30,7 @@
2730
"lint": "eslint ./src",
2831
"lint:scss": "stylelint ./src",
2932
"postinstall": "./node_modules/.bin/cpy \"./config/config.example.js\" \"./config\" --no-overwrite --rename=\"config.js\"",
30-
"precommit": "lint-staged",
33+
"precommit": "npm run analyse:size && lint-staged",
3134
"prepush": "npm test",
3235
"start": "webpack-dev-server --hot --config webpack/dev.config.js",
3336
"test": "jest",
@@ -47,6 +50,18 @@
4750
"jest --findRelatedTests"
4851
]
4952
},
53+
"size-limit": [
54+
{
55+
"limit": "100 KB",
56+
"webpack": false,
57+
"path": "dist/src/*.client.bundled.js"
58+
},
59+
{
60+
"limit": "550 KB",
61+
"webpack": false,
62+
"path": "dist/src/*.vendors~client.bundled.js"
63+
}
64+
],
5065
"peerDependencies": {
5166
"material-ui": "1.0.0-beta.36",
5267
"material-ui-icons": "1.0.0-beta.36",
@@ -109,6 +124,7 @@
109124
"prettier": "1.12.1",
110125
"redux-mock-store": "1.5.1",
111126
"sass-loader": "7.0.1",
127+
"size-limit": "0.18.1",
112128
"stylelint": "9.2.0",
113129
"stylelint-config-sass-guidelines": "5.0.0",
114130
"uglifyjs-webpack-plugin": "1.2.5",

src/components/trello-cards-list/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Typography from 'material-ui/Typography'
55
import { LinearProgress } from 'material-ui/Progress'
66
import styled from 'styled-components'
77

8-
import proptypes from './prop-types'
8+
import proptypes from './prop-types' // eslint-disable-line
99
import TrelloCard from '../trello-card'
1010

1111
const ColumnContainer = styled.div`

src/components/trello-cards-list/prop-types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const proptypes = {
1818
cards: PropTypes.arrayOf(
1919
PropTypes.shape({
2020
card,
21-
...listConfig,
21+
listConfig,
2222
}),
2323
),
2424
config: listConfig,
@@ -27,3 +27,5 @@ export const proptypes = {
2727
list,
2828
loadCards: PropTypes.func.isRequired,
2929
}
30+
31+
export default proptypes

webpack/prod.analyse.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const production = require('./prod.config.js')
2+
const merge = require('webpack-merge')
3+
const Jarvis = require('webpack-jarvis')
4+
5+
module.exports = merge(production, {
6+
plugins: [
7+
new Jarvis({
8+
port: 3333,
9+
watchOnly: false
10+
}),
11+
]
12+
})

webpack/prod.config.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const common = require('./base.config.js')
22
const merge = require('webpack-merge')
3-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
3+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
44

55
module.exports = merge(common, {
66
mode: 'production',
@@ -12,13 +12,29 @@ module.exports = merge(common, {
1212
// https://webpack.js.org/plugins/split-chunks-plugin/
1313
splitChunks: {
1414
chunks: 'initial' // default splitting, or 'all'
15-
}
16-
},
15+
},
16+
// inspired by and some issues to read more about treeshaking in webpack
17+
// - https://github.com/gpspake/es6-todomvc/blob/c6e30fc6676ec362f3f4be8ec41df27c12007b8b/webpack.config.babel.js
18+
// - https://stackoverflow.com/a/47675519/1238150 (treeshaking w/ change in .babelrc)
19+
// - see also: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/247#issuecomment-370911955
20+
// - https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/267 (Webpack 4 Issue)
21+
// - https://github.com/webpack/webpack/issues/6992 (Webpack 4 Issue)
22+
minimizer: [
23+
new UglifyJsPlugin({
24+
parallel: true,
25+
sourceMap: false,
26+
uglifyOptions: {
27+
compress: {
28+
drop_console: true,
29+
dead_code: true,
30+
},
31+
output: {
32+
beautify: false,
33+
comments: false,
34+
}
35+
}
36+
})
37+
]
38+
}
1739

18-
plugins: [
19-
new UglifyJSPlugin({
20-
parallel: true,
21-
sourceMap: false
22-
})
23-
]
2440
})

0 commit comments

Comments
 (0)