Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #184 from TrueCar/toddw/size-optimizations
Browse files Browse the repository at this point in the history
Bundle Size Optimization Updates
  • Loading branch information
christinebrass committed May 23, 2016
2 parents 4dd9fdf + f4e8ea7 commit a5bf2c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/commands/start-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require("fs");
const path = require("path");
const webpack = require("webpack");
const process = require("process");
Expand All @@ -7,7 +8,7 @@ const WebpackIsomorphicToolsPlugin = require("webpack-isomorphic-tools/plugin");
const webpackSharedConfig = require("../config/webpack-shared-config");
const detectEnvironmentVariables = require("../lib/detectEnvironmentVariables");
const getWebpackAdditions = require("../lib/getWebpackAdditions").default;
const { additionalLoaders, additionalPreLoaders, vendor } = getWebpackAdditions();
const { additionalLoaders, additionalPreLoaders, vendor, plugins } = getWebpackAdditions();
const logger = require("../lib/logger");
const logsColorScheme = require("../lib/logsColorScheme");

Expand Down Expand Up @@ -100,7 +101,7 @@ const compiler = webpack({
new webpack.IgnorePlugin(/\.server(\.js)?$/),
new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js"),
new webpack.optimize.AggressiveMergingPlugin()
].concat(environmentPlugins, webpackSharedConfig.plugins),
].concat(environmentPlugins, webpackSharedConfig.plugins, plugins),
resolve: {
...webpackSharedConfig.resolve
}
Expand Down Expand Up @@ -137,6 +138,7 @@ module.exports = function (buildOnly) {
else {
logger.info("Bundling assets…");
compiler.run((error, stats) => {
fs.writeFileSync("webpack-bundle-stats.json", JSON.stringify(stats.toJson()));
const errors = stats.toJson().errors;
if (errors.length) {
errors.forEach((e) => {
Expand Down
8 changes: 5 additions & 3 deletions src/lib/getWebpackAdditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default function (isomorphic=false) {
let userAdditions = {
additionalLoaders: [],
additionalPreLoaders: [],
vendor: []
vendor: [],
plugins: []
};

// Babel will try to resolve require statements ahead of time which will cause an error
Expand All @@ -51,11 +52,12 @@ export default function (isomorphic=false) {
try {
const webpackAdditionsPath = path.join(process.cwd(), "src", "config", "webpack-additions.js");
fs.statSync(webpackAdditionsPath);
const { additionalLoaders, additionalPreLoaders, vendor } = require(webpackAdditionsPath);
const { additionalLoaders, additionalPreLoaders, vendor, plugins } = require(webpackAdditionsPath);
userAdditions = {
additionalLoaders: isomorphic ? additionalLoaders : prepareUserAdditionsForWebpack(additionalLoaders),
additionalPreLoaders: isomorphic ? additionalPreLoaders : prepareUserAdditionsForWebpack(additionalPreLoaders),
vendor: vendor || []
vendor: vendor || [],
plugins: plugins || []
};
}
catch (e) {
Expand Down
1 change: 1 addition & 0 deletions templates/new/_gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Output from webpack asset bunlding
webpack-assets.json
webpack-bundle-stats.json

# Logs
logs
Expand Down
5 changes: 3 additions & 2 deletions templates/new/src/config/.entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { render } from "react-dom";
import "../../Index.js";

import { Root, getHttpClient } from "gluestick-shared";
import { match, browserHistory as history } from "react-router";
import match from "react-router/lib/match";
import browserHistory from "react-router/lib/browserHistory";
import routes from "./routes";
import store from "./.store";
import { StyleRoot } from "radium";
Expand Down Expand Up @@ -44,7 +45,7 @@ export default class Entry extends Component {

Entry.start = function () {
const newStore = store(httpClient);
match({ history, routes: getRoutes(newStore) }, (error, redirectLocation, renderProps) => {
match({ history: browserHistory, routes: getRoutes(newStore) }, (error, redirectLocation, renderProps) => {
render(<Entry radiumConfig={{userAgent: window.navigator.userAgent}} store={newStore} {...renderProps} />, document.getElementById("main"));
});
};
Expand Down

0 comments on commit a5bf2c3

Please sign in to comment.