Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit f7fd2a5

Browse files
committed
Merge branch 'feat_rc_webpack_config'
2 parents a61e5eb + c838dfd commit f7fd2a5

File tree

8 files changed

+112
-52
lines changed

8 files changed

+112
-52
lines changed

config/templates/_index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv=X-UA-Compatible content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1">
7+
<title>Scalable React Boilerplate</title>
8+
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
9+
</head>
10+
<body>
11+
<!-- The app will bootstrap into this div -->
12+
<div id="app"></div>
13+
14+
</body>
15+
</html>

config/testing/__mocks__/.gitkeep

Whitespace-only changes.

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<!doctype html>
2-
<!doctype html>
32
<html lang="en">
43
<head>
54
<meta charset="UTF-8">
65
<meta http-equiv=X-UA-Compatible content="IE=edge">
7-
<meta name=viewport content="width=device-width,initial-scale=1">
6+
<meta name="viewport" content="width=device-width,initial-scale=1">
87
<title>Scalable React Boilerplate</title>
98
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
109
</head>

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"test": {
1515
"plugins": [
1616
[
17-
"babel-plugin-webpack-loaders",
18-
{
17+
"babel-plugin-webpack-loaders", {
1918
"config": "./config/testing/webpack.test.config.js",
2019
"verbose": false
2120
}
@@ -40,18 +39,17 @@
4039
"configFile": "./config/webpack/webpack.test.config.js"
4140
},
4241
"scripts": {
43-
"t": "BABEL_DISABLE_CACHE=1 NODE_ENV=test node --harmony_proxies node_modules/.bin/jest",
42+
"t": "npm run test",
4443
"test:watch": "npm test -- --watch",
45-
"test": "npm run t",
44+
"test": "BABEL_DISABLE_CACHE=1 NODE_ENV=test node --harmony_proxies node_modules/.bin/jest",
4645
"build": "webpack",
4746
"dev": "webpack-dev-server",
4847
"generate": "plop --plopfile config/generators/index.js",
49-
"generator": "npm run generate",
5048
"generate:component": "plop --plopfile config/generators/index.js component",
5149
"generate:container": "plop --plopfile config/generators/index.js container",
5250
"generate:page": "plop --plopfile config/generators/index.js page",
5351
"lint": "eslint . --ext .js --ext .jsx; exit 0",
54-
"deploy": "cross-env NODE_ENV=production webpack -p",
52+
"deploy": "cross-env NODE_ENV=production webpack",
5553
"start": "npm run dev",
5654
"clean": "rm -rf app/dist app/build",
5755
"setup": "npm install",
@@ -92,6 +90,7 @@
9290
"expect": "^1.20.2",
9391
"expect-jsx": "^2.6.0",
9492
"express": "^4.14.0",
93+
"extract-text-webpack-plugin": "^1.0.1",
9594
"file-loader": "^0.9.0",
9695
"foundation-sites": "^6.2.3",
9796
"grommet": "^0.6.10",

server/public/index.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
<!doctype html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta http-equiv=X-UA-Compatible content="IE=edge">
6-
<meta name=viewport content="width=device-width,initial-scale=1">
7-
<title>Scalable React Boilerplate</title>
8-
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
9-
</head>
10-
<body>
11-
<!-- The app will bootstrap into this div -->
12-
<div id="app"></div>
13-
<script type="text/javascript" src="/bundle.js"></script>
14-
</body>
15-
</html>
1+
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Scalable React Boilerplate</title><link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700" rel="stylesheet"></head><body><div id="app"></div><script type="text/javascript" src="/vendor.26f395b8adac3b23a24c.js"></script><script type="text/javascript" src="/main.1e58d1cb696f4b75ca7b.js"></script></body></html>

server/public/main.1e58d1cb696f4b75ca7b.js

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/public/vendor.26f395b8adac3b23a24c.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack.config.babel.js

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ import path from 'path';
33
import HtmlwebpackPlugin from 'html-webpack-plugin';
44
import NpmInstallPlugin from 'npm-install-webpack-plugin';
55
import Visualizer from 'webpack-visualizer-plugin';
6-
const ROOT_PATH = path.resolve(__dirname);
6+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
77

8+
const ROOT_PATH = path.resolve(__dirname);
89
const env = process.env.NODE_ENV || 'development';
10+
const isProduction = env === 'production';
911
const PORT = process.env.PORT || 1337;
1012
const HOST = '0.0.0.0'; // Set to localhost if need be.
1113

1214
module.exports = {
13-
devtool: process.env.NODE_ENV === 'production' ? '' : 'source-map',
15+
devtool: isProduction ? '' : 'source-map',
1416
entry: [
1517
path.resolve(ROOT_PATH,'app/src/index')
1618
],
1719
module: {
1820
preLoaders: [
1921
{
2022
test: /\.jsx?$/,
21-
loaders: process.env.NODE_ENV === 'production' ? [] : ['eslint'],
23+
loaders: isProduction ? [] : ['eslint'],
2224
include: path.resolve(ROOT_PATH, './app')
2325
}
2426
],
@@ -75,13 +77,17 @@ module.exports = {
7577
pages: path.resolve(ROOT_PATH, 'app/src/pages')
7678
},
7779
},
78-
output: { // Set output to public folder in production
79-
path: process.env.NODE_ENV === 'production' ?
80+
output: {
81+
path: isProduction ?
8082
path.resolve(ROOT_PATH, 'server/public')
8183
:
8284
path.resolve(ROOT_PATH, 'app/build'),
8385
publicPath: '/',
84-
filename: 'bundle.js',
86+
filename: isProduction ? '[name].[chunkhash].js' : 'bundle.js',
87+
chunkFilename: '[name].[chunkhash].chunk.js',
88+
},
89+
stats: {
90+
chunks: isProduction,
8591
},
8692
devServer: {
8793
contentBase: path.resolve(ROOT_PATH, 'app/build'),
@@ -94,27 +100,48 @@ module.exports = {
94100
host: HOST,
95101
port: PORT
96102
},
97-
plugins: process.env.NODE_ENV === 'production' ?
98-
[
99-
new webpack.DefinePlugin({
100-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
101-
}),
102-
new webpack.optimize.OccurrenceOrderPlugin(true),
103-
new webpack.optimize.DedupePlugin(),
104-
new webpack.optimize.UglifyJsPlugin({
105-
compress: {
106-
warnings: false,
107-
},
108-
}),
109-
]
110-
:
111-
[
112-
new webpack.HotModuleReplacementPlugin(),
113-
new NpmInstallPlugin(),
114-
new HtmlwebpackPlugin({
115-
title: 'Scalable React Boilerplate',
116-
template: 'index.html'
117-
}),
118-
new Visualizer()
119-
]
103+
plugins: isProduction ?
104+
[
105+
new ExtractTextPlugin('[name].[contenthash].css'),
106+
new webpack.optimize.CommonsChunkPlugin({
107+
name: 'vendor',
108+
children: true,
109+
minChunks: 2,
110+
async: true,
111+
}),
112+
new HtmlwebpackPlugin({
113+
template: 'config/templates/_index.html',
114+
minify: {
115+
removeComments: true,
116+
collapseWhitespace: true,
117+
removeRedundantAttributes: true,
118+
useShortDoctype: true,
119+
removeEmptyAttributes: true,
120+
removeStyleLinkTypeAttributes: true,
121+
keepClosingSlash: true,
122+
minifyJS: true,
123+
minifyCSS: true,
124+
minifyURLs: true,
125+
},
126+
inject: true,
127+
}),
128+
new webpack.DefinePlugin({
129+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
130+
}),
131+
new webpack.optimize.OccurrenceOrderPlugin(true),
132+
new webpack.optimize.DedupePlugin(),
133+
new webpack.optimize.UglifyJsPlugin({
134+
sourceMap: false
135+
}),
136+
]
137+
:
138+
[
139+
new webpack.HotModuleReplacementPlugin(),
140+
new NpmInstallPlugin(),
141+
new HtmlwebpackPlugin({
142+
title: 'Scalable React Boilerplate',
143+
template: 'index.html'
144+
}),
145+
new Visualizer()
146+
]
120147
};

0 commit comments

Comments
 (0)