Skip to content

Commit 6e85768

Browse files
committed
Updated to the latest webpack and babel
1 parent fef130a commit 6e85768

File tree

4 files changed

+86
-56
lines changed

4 files changed

+86
-56
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015-native-modules", "react"],
2+
"presets": [["es2015", { "modules": false }], "react"],
33
"plugins": ["transform-runtime"]
44
}

build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint no-var: 0 */
22
var exec = require('child_process').exec;
33

4-
var cmdLine = './node_modules/.bin/webpack --progress';
4+
var executable = (!process.argv[3].indexOf('server')) ? 'webpack-dev-server' : 'webpack';
5+
var cmdLine = './node_modules/.bin/' + executable;
56
var environ = (!process.argv[2].indexOf('development')) ? 'development' : 'production';
67
var command;
78

package.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66
"author": "Grgur Grisogono",
77
"main": "index.js",
88
"scripts": {
9-
"start": "./node_modules/.bin/webpack-dev-server --history-api-fallback --hot --progress --port 3000",
10-
"build": "node build.js production"
9+
"start": "webpack-dev-server --config webpack.config.js",
10+
"prod": "node build.js production server",
11+
"build": "node build.js production filesystem"
1112
},
1213
"license": "MIT",
1314
"devDependencies": {
14-
"babel-core": "^6.6.5",
15-
"babel-loader": "^6.2.4",
16-
"babel-plugin-transform-runtime": "^6.6.0",
17-
"babel-preset-es2015-native-modules": "^6.6.0",
18-
"babel-preset-react": "^6.5.0",
19-
"css-loader": "^0.23.1",
20-
"extract-text-webpack-plugin": "^2.0.0-beta.3",
15+
"babel-core": "^6.16.0",
16+
"babel-loader": "^6.2.7",
17+
"babel-plugin-transform-runtime": "^6.15.0",
18+
"babel-preset-es2015": "^6.18.0",
19+
"babel-preset-react": "^6.15.0",
20+
"css-loader": "0.14.5",
21+
"extract-text-webpack-plugin": "^2.0.0-beta.4",
2122
"file-loader": "^0.8.5",
22-
"node-sass": "^3.5.0-beta.1",
23-
"sass-loader": "^3.1.2",
24-
"style-loader": "^0.13.0",
23+
"node-sass": "^3.12.2",
24+
"sass-loader": "^4",
25+
"style-loader": "^0.13.1",
2526
"webpack": "^2.1.0-beta.4",
26-
"webpack-dev-server": "^2.0.0-beta"
27+
"webpack-dev-server": "^2.1.0-beta.10"
2728
},
2829
"dependencies": {
29-
"babel-polyfill": "^6.6.1",
30-
"babel-runtime": "^6.6.1",
31-
"react": "^15.0.0-rc.1",
32-
"react-dom": "^15.0.0-rc.1",
33-
"react-router": "^2.0.0"
30+
"babel-polyfill": "^6.16.0",
31+
"babel-runtime": "^6.16.0",
32+
"react": "^15.3.0",
33+
"react-dom": "^15.3.0",
34+
"react-router": "^2.8.0"
3435
}
3536
}

webpack.config.js

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,53 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
44

55
const nodeEnv = process.env.NODE_ENV || 'development';
66
const isProd = nodeEnv === 'production';
7-
let extractCSS = new ExtractTextPlugin('style.css');
7+
8+
const sourcePath = path.join(__dirname, './client');
9+
const staticsPath = path.join(__dirname, './static');
10+
11+
const extractCSS = new ExtractTextPlugin('style.css');
12+
13+
const plugins = [
14+
new webpack.optimize.CommonsChunkPlugin({
15+
name: 'vendor',
16+
minChunks: Infinity,
17+
filename: 'vendor.bundle.js'
18+
}),
19+
new webpack.DefinePlugin({
20+
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
21+
}),
22+
];
23+
24+
if (isProd) {
25+
plugins.push(
26+
new webpack.LoaderOptionsPlugin({
27+
minimize: true,
28+
debug: false
29+
}),
30+
new webpack.optimize.UglifyJsPlugin({
31+
compress: {
32+
warnings: false,
33+
screw_ie8: true,
34+
conditionals: true,
35+
unused: true,
36+
comparisons: true,
37+
sequences: true,
38+
dead_code: true,
39+
evaluate: true,
40+
if_return: true,
41+
join_vars: true,
42+
},
43+
output: {
44+
comments: false
45+
},
46+
}),
47+
extractCSS
48+
);
49+
}
850

951
module.exports = {
10-
devtool: isProd ? 'hidden-source-map' : 'cheap-eval-source-map',
11-
context: path.join(__dirname, './client'),
52+
devtool: isProd ? 'source-map' : 'eval',
53+
context: sourcePath,
1254
entry: {
1355
js: [
1456
'index',
@@ -20,29 +62,34 @@ module.exports = {
2062
]
2163
},
2264
output: {
23-
path: path.join(__dirname, './static'),
65+
path: staticsPath,
2466
filename: 'bundle.js',
2567
publicPath: '/',
2668
},
2769
module: {
28-
loaders: [
70+
rules: [
2971
{
3072
test: /\.html$/,
31-
loader: 'file',
73+
loader: 'file-loader',
3274
query: {
3375
name: '[name].[ext]'
3476
}
3577
},
3678
{
3779
test: /\.scss$/,
38-
loaders: extractCSS.extract(['css','sass'])
80+
loaders: isProd ?
81+
extractCSS.extract({
82+
fallbackLoader: 'style-loader',
83+
loader: ['css-loader', 'sass-loader'],
84+
}) :
85+
['style-loader', 'css-loader', 'sass-loader']
3986
},
4087
{
4188
test: /\.(js|jsx)$/,
4289
exclude: /node_modules/,
4390
loaders: [
4491
{
45-
loader: 'babel',
92+
loader: 'babel-loader',
4693
query: {
4794
cacheDirectory: true
4895
}
@@ -51,43 +98,24 @@ module.exports = {
5198
},
5299
{
53100
test: /\.(gif|png|jpg|jpeg\ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
54-
loader: 'file'
101+
loader: 'file-loader'
55102
}
56103
],
57104
},
58105
resolve: {
59-
extensions: ['', '.js', '.jsx'],
106+
extensions: ['.js', '.jsx'],
60107
modules: [
61-
path.resolve('./client'),
108+
sourcePath,
62109
'node_modules'
63110
]
64111
},
65-
plugins: [
66-
new webpack.optimize.CommonsChunkPlugin({
67-
name: 'vendor',
68-
minChunks: Infinity,
69-
filename: 'vendor.bundle.js'
70-
}),
71-
new webpack.LoaderOptionsPlugin({
72-
minimize: true,
73-
debug: false
74-
}),
75-
new webpack.optimize.UglifyJsPlugin({
76-
compress: {
77-
warnings: false
78-
},
79-
output: {
80-
comments: false
81-
},
82-
sourceMap: false
83-
}),
84-
new webpack.DefinePlugin({
85-
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
86-
}),
87-
extractCSS,
88-
],
112+
plugins: plugins,
89113
devServer: {
90114
contentBase: './client',
91-
noInfo: true
115+
historyApiFallback: true,
116+
inject: true,
117+
port: 3000,
118+
compress: isProd,
119+
stats: { colors: true },
92120
}
93121
};

0 commit comments

Comments
 (0)