Skip to content

Commit 90d11fa

Browse files
committed
Updated to latest hot module reloading (compatible with Babel6). Move client into app. Remove webpack server
1 parent b5595c9 commit 90d11fa

File tree

8 files changed

+66
-76
lines changed

8 files changed

+66
-76
lines changed

.babelrc

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"presets": [
3-
"es2015",
4-
"react"
5-
],
6-
"ignore": [
7-
"node_modules"
8-
]
2+
"presets": [ "es2015", "react" ],
3+
"ignore": [ "node_modules" ]
94
}

.eslintrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"es6": true
66
},
77
"ecmaFeatures": {
8-
"modules": true
9-
}
8+
"modules": true,
9+
"jsx": true
10+
},
11+
"plugins": [ "babel", "react" ]
1012
}

app/.eslintrc

+1-29
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,9 @@
44
"browser": true,
55
"es6": true
66
},
7-
"plugins": [ "react" ],
87
"ecmaFeatures": {
98
"jsx": true,
109
"modules": true
1110
},
12-
"rules": {
13-
"react/display-name": [ 1, { "acceptTranspilerName": true }],
14-
"react/jsx-boolean-value": 1,
15-
"react/jsx-closing-bracket-location": 1,
16-
"react/jsx-curly-spacing": 1,
17-
"react/jsx-indent-props": 1,
18-
"react/jsx-max-props-per-line": 0,
19-
"react/jsx-no-duplicate-props": 1,
20-
"react/jsx-no-literals": 0,
21-
"react/jsx-no-undef": 1,
22-
"react/jsx-quotes": 1,
23-
"react/jsx-sort-prop-types": 1,
24-
"react/jsx-sort-props": 0,
25-
"react/jsx-uses-react": 1,
26-
"react/jsx-uses-vars": 1,
27-
"react/no-danger": 1,
28-
"react/no-did-mount-set-state": 1,
29-
"react/no-did-update-set-state": 1,
30-
"react/no-multi-comp": 1,
31-
"react/no-set-state": 1,
32-
"react/no-unknown-property": 1,
33-
"react/prop-types": 1,
34-
"react/react-in-jsx-scope": 1,
35-
"react/require-extension": 1,
36-
"react/self-closing-comp": 1,
37-
"react/sort-comp": 1,
38-
"react/wrap-multilines": 1
39-
}
11+
"plugins": [ "babel", "react" ]
4012
}

client/client.jsx app/client/client.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import MainComponent from '../app/components/Main.jsx';
3+
import MainComponent from '../components/Main.jsx';
44

5-
import '../app/scss/main.scss';
5+
import '../scss/main.scss';
66

77
window.addEventListener('load', () => {
88
ReactDOM.render(<MainComponent />, document.getElementById('app-container'));

package.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,37 @@
2121
"author": "Thomas Pedersen",
2222
"devDependencies": {
2323
"autoprefixer-loader": "^3.1.0",
24-
"babel-eslint": "^5.0.0-beta2",
24+
"babel-core": "^6.3.15",
25+
"babel-plugin-transform-react-constant-elements": "^6.3.13",
26+
"babel-plugin-transform-react-inline-elements": "^6.3.13",
27+
"babel-eslint": "^5.0.0-beta4",
2528
"babel-loader": "^6.2.0",
26-
"babel-preset-es2015": "^6.1.18",
27-
"babel-preset-react": "^6.1.18",
29+
"babel-plugin-react-transform": "^2.0.0-beta1",
30+
"babel-preset-es2015": "^6.3.13",
31+
"babel-preset-react": "^6.3.13",
2832
"css-loader": "^0.23.0",
29-
"eslint": "^1.10.2",
33+
"eslint": "^1.10.3",
3034
"eslint-loader": "^1.1.1",
31-
"eslint-plugin-react": "^3.10.0",
35+
"eslint-plugin-babel": "^3.0.0",
36+
"eslint-plugin-react": "^3.11.3",
3237
"extract-text-webpack-plugin": "^0.9.1",
3338
"file-loader": "^0.8.5",
3439
"merge": "^1.2.0",
40+
"node-sass": "^3.4.2",
41+
"react-transform-catch-errors": "^1.0.0",
42+
"react-transform-hmr": "^1.0.1",
43+
"redbox-react": "^1.2.0",
3544
"rimraf": "^2.4.4",
3645
"sass-loader": "^3.1.2",
3746
"style-loader": "^0.13.0",
3847
"url-loader": "^0.5.7",
3948
"webpack": "^1.12.9",
4049
"webpack-dev-middleware": "^1.4.0",
41-
"webpack-dev-server": "^1.14.0",
4250
"webpack-hot-middleware": "^2.6.0"
4351
},
4452
"dependencies": {
45-
"babel-core": "^6.2.4",
4653
"body-parser": "^1.14.1",
4754
"express": "^4.11.2",
48-
"node-sass": "^3.4.2",
4955
"react": "^0.14.3",
5056
"react-dom": "^0.14.3"
5157
}

server/server.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ const renderPage = (html) => {
3535

3636
if (process.env.NODE_ENV !== 'production') {
3737
const compiler = webpack(webpackConfig);
38-
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
38+
app.use(webpackDevMiddleware(compiler, {
39+
noInfo: true,
40+
publicPath: webpackConfig.output.publicPath })
41+
);
3942
app.use(webpackHotMiddleware(compiler));
4043
} else {
4144
app.use('/static', express.static(__dirname + '/../dist'));
@@ -47,7 +50,7 @@ app.use((req, res, next) => {
4750
});
4851

4952
const server = app.listen(3002, () => {
50-
const host =server.address().address;
53+
const host = server.address().address;
5154
const port = server.address().port;
5255
console.log(`Listening at http://${host}:${port}`);
5356
});

server/webpack.js

-14
This file was deleted.

webpack.config.js

+38-12
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,33 @@ var webpackConfig = {
3737
]
3838
};
3939

40+
var babelSettings = {
41+
presets: ['react', 'es2015'],
42+
env: {
43+
development: {
44+
plugins: [
45+
['react-transform', {
46+
transforms: [
47+
{
48+
transform: 'react-transform-hmr',
49+
imports: [ 'react'],
50+
locals: [ 'module' ]
51+
},
52+
{
53+
transform: 'react-transform-catch-errors',
54+
imports: [ 'react', 'redbox-react' ]
55+
}
56+
]
57+
}]
58+
]
59+
}
60+
}
61+
};
62+
4063
if (process.env.NODE_ENV === 'production') {
4164
webpackConfig = merge(webpackConfig, {
4265
entry: [
43-
'./client/client.jsx'
66+
'./app/client/client.jsx'
4467
],
4568
module: {
4669
loaders: [
@@ -49,7 +72,11 @@ if (process.env.NODE_ENV === 'production') {
4972
loader: 'babel',
5073
exclude: /node_modules/,
5174
query: {
52-
presets: ['react', 'es2015']
75+
presets: ['react', 'es2015'],
76+
plugins: [
77+
"transform-react-inline-elements",
78+
"transform-react-constant-elements"
79+
]
5380
},
5481
include: __dirname
5582
},
@@ -66,24 +93,23 @@ if (process.env.NODE_ENV === 'production') {
6693
}
6794
}),
6895
new ExtractTextPlugin('app.css'),
69-
new webpack.optimize.UglifyJsPlugin({ minimize: true })
96+
new webpack.optimize.UglifyJsPlugin({
97+
minimize: true,
98+
compress: {
99+
warnings: false
100+
}
101+
})
70102
]
71103
});
72104
} else {
73105
webpackConfig = merge(webpackConfig, {
74106
devtool: 'inline-source-map',
75107
module: {
76-
preLoaders: [
77-
{ test: /\.(js|jsx)$/, loaders: ['eslint'] }
78-
],
79108
loaders: [
80109
{
81110
test: /\.(js|jsx)$/,
82-
loader: 'babel',
83-
exclude: /node_modules/,
84-
query: {
85-
presets: ['react', 'es2015']
86-
}
111+
loaders: ['babel?' + JSON.stringify(babelSettings)],
112+
exclude: /node_modules/
87113
},
88114
{
89115
test: /\.scss$/,
@@ -93,7 +119,7 @@ if (process.env.NODE_ENV === 'production') {
93119
},
94120
entry: [
95121
'webpack-hot-middleware/client',
96-
'./client/client.jsx'
122+
'./app/client/client.jsx'
97123
],
98124
plugins: [
99125
new webpack.HotModuleReplacementPlugin()

0 commit comments

Comments
 (0)