Skip to content

Commit 62637e9

Browse files
separating vendors, minigying bundles, diff node config, diff babel config, multiple node instances.
1 parent b4d03e0 commit 62637e9

File tree

6 files changed

+50
-17
lines changed

6 files changed

+50
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ coverage
2424
.lock-wscript
2525

2626
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
27+
build
2828

2929
# Dependency directories
3030
node_modules

lib/bundle.js

Whitespace-only changes.

lib/components/App.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ class App extends React.PureComponent {
5555
//TODO: Leaving this purposely uncommented. Be aware that in production this has to be commented.
5656
//We need consistent measures that's why we need to add this lines so we messure the components at the same point
5757
//Those numbers need to be the same every time we refresh
58-
setImmediate(()=>{Perf.start();});
59-
setTimeout(()=>{ Perf.stop();
60-
Perf.printWasted();},5000);
58+
//setImmediate(()=>{Perf.start();});
59+
//setTimeout(()=>{ Perf.stop();
60+
//Perf.printWasted();},5000);
6161
}
6262

6363
componentWillUnmount() {
6464
this.props.store.unsubscribe(this.subscriptionId);
6565
}
6666

67-
componentWillUpdate(nextProps, nextState)
68-
{
69-
console.log('Updating TimeStamp');
70-
}
67+
//This life cylce method can help us to identify where can we improve our optimization
68+
// componentWillUpdate(nextProps, nextState)
69+
// {
70+
// console.log('Updating TimeStamp');
71+
// }
7172

7273
//In react we cannot return two elements unless
7374
//Option 1. is in an array so we need to pass a Key elements

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@
2929
"update-snapshot":"jest --updateSnapshot",
3030
"test": "jest --watch",
3131
"verify-tests": "jest --coverage",
32-
"dev": "NODE_PATH=./lib pm2 start lib/server.js --watch --interpreter babel-node",
33-
"webpack": "webpack -wd"
32+
"dev": "NODE_PATH=./lib pm2 start lib/server.js --watch --interpreter babel-node --name appDev",
33+
"webpack": "webpack -wd",
34+
"build-webpack" : "webpack -p",
35+
"build-node" : "babel lib -d build --copy-files",
36+
"start-prod": "NODE_ENV=production NODE_PATH=./build pm2 start build/server.js -i max --name appProd"
37+
3438
},
3539
"babel": {
3640
"presets": [
3741
"react",
38-
"env",
39-
"stage-2"
42+
["env", {"targets" : {"node" : "current" }}]
43+
],
44+
"plugins" : [
45+
"transform-class-properties",
46+
"transform-object-rest-spread"
4047
]
4148
},
4249
"devDependencies": {

views/index.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<div id="root"><%- initialMarkup -%></div>
1717

1818
<!-- Nowadays it is a good practice to make reference to just one file so we do not have multiple references -->
19-
<script src="/bundle.js" charset="UTF-8"></script>
19+
<!-- todo: Ideally we should automate the regeneration of this file to an incremental version (1,2,3...) according to our deployment -->
20+
<script src="/vendor.js?version=1" charset="UTF-8"></script>
21+
<script src="/app.js?version=1" charset="UTF-8"></script>
2022
</body>
2123
</html>

webpack.config.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const webpack = require ('webpack');
23

34
//adding the resolve section allow us to tell webpack that if it sees a require, it also need to look in the
45
//lib and node_modules folder
@@ -7,16 +8,38 @@ const config = {
78
path.resolve('./lib'),
89
path.resolve('./node_modules'),
910
]},
10-
entry: [ 'babel-polyfill', './lib/renderers/dom.js'],
11+
entry: {
12+
vendor: ['babel-polyfill', 'react', 'react-dom', 'prop-types', 'axios', 'lodash.debounce', 'lodash.pickby'],
13+
app: ['./lib/renderers/dom.js']
14+
},
1115
output: {
1216
path: path.resolve(__dirname, 'public'),
13-
filename: 'bundle.js'
17+
filename: '[name].js'
1418
},
1519
module: {
1620
rules: [
17-
{ test: /\.js$/, exclude:/node_modules/, use: 'babel-loader' }
21+
{
22+
test: /\.js$/, exclude: /node_modules/,
23+
use: {
24+
loader: 'babel-loader',
25+
options: {
26+
presets:['react', 'env', 'stage-2']
27+
}
28+
}
29+
}
1830
]
19-
}
31+
},
32+
plugins: [
33+
new webpack.optimize.CommonsChunkPlugin({
34+
name: "vendor",
35+
// filename: "vendor.js"
36+
// (Give the chunk a different name)
37+
38+
minChunks: Infinity,
39+
// (with more entries, this ensures that no other module
40+
// goes into the vendor chunk)
41+
})
42+
]
2043
};
2144

2245
module.exports = config;

0 commit comments

Comments
 (0)