Skip to content

Commit

Permalink
Merge pull request #775 from weaveworks/build-performance
Browse files Browse the repository at this point in the history
Speed up npm bundle builds
  • Loading branch information
davkal committed Dec 16, 2015
2 parents c85f0df + 57dfe4a commit 4ea8545
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div id="app"></div>
</div>

<script src="vendors.js"></script>
<script src="app.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions client/build/terminal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div id="app"></div>
</div>

<script src="vendors.js"></script>
<script src="terminal-app.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"webpack-dev-server": "~1.12.1"
},
"scripts": {
"build": "webpack -p --config webpack.production.config.js",
"build": "webpack --config webpack.production.config.js",
"start": "node server.js",
"start-production": "NODE_ENV=production node server.js",
"test": "jest",
Expand Down
2 changes: 1 addition & 1 deletion client/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var app = express();


// Serve application file depending on environment
app.get(/(app|terminal-app).js/, function(req, res) {
app.get(/(app|terminal-app|vendors).js/, function(req, res) {
var filename = req.originalUrl;
if (process.env.NODE_ENV === 'production') {
res.sendFile(__dirname + '/build' + filename);
Expand Down
9 changes: 8 additions & 1 deletion client/webpack.local.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ module.exports = {
'./app/scripts/terminal-main',
'webpack-dev-server/client?http://localhost:4041',
'webpack/hot/only-dev-server'
]
],
vendors: ['classnames', 'd3', 'dagre', 'flux', 'immutable',
'lodash', 'page', 'react', 'react-dom', 'react-motion']
},

// This will not actually create a app.js file in ./build. It is used
Expand All @@ -45,12 +47,17 @@ module.exports = {

// Necessary plugins for hot load
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],

// Transform source code using Babel and React Hot Loader
module: {
include: [
path.resolve(__dirname, 'app/scripts')
],

preLoaders: [
{
test: /\.js$/,
Expand Down
12 changes: 11 additions & 1 deletion client/webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ module.exports = {
// fail on first error when building release
bail: true,

cache: {},

entry: {
app: './app/scripts/main',
'terminal-app': './app/scripts/terminal-main'
'terminal-app': './app/scripts/terminal-main',
vendors: ['classnames', 'd3', 'dagre', 'flux', 'immutable',
'lodash', 'page', 'react', 'react-dom', 'react-motion']
},

output: {
Expand All @@ -25,6 +29,9 @@ module.exports = {
},

module: {
include: [
path.resolve(__dirname, 'app/scripts')
],
preLoaders: [
{
test: /\.js$/,
Expand Down Expand Up @@ -65,7 +72,10 @@ module.exports = {

plugins: [
new webpack.DefinePlugin(GLOBALS),
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
warnings: false
}
Expand Down

0 comments on commit 4ea8545

Please sign in to comment.