File tree Expand file tree Collapse file tree 7 files changed +84
-17
lines changed Expand file tree Collapse file tree 7 files changed +84
-17
lines changed Original file line number Diff line number Diff line change 1
- import { Route , IndexRoute } from 'react-router' ;
2
- import React from 'react' ;
3
1
import App from './modules/App/App' ;
4
- import PostListPage from './modules/Post/pages/PostListPage/PostListPage' ;
5
- import PostDetailPage from './modules/Post/pages/PostDetailPage/PostDetailPage' ;
6
2
7
- const routes = (
8
- < Route path = "/" component = { App } >
9
- < IndexRoute component = { PostListPage } />
10
- < Route path = "/post/:slug" component = { PostDetailPage } />
11
- </ Route >
12
- ) ;
3
+ function errorLoading ( err ) {
4
+ console . error ( 'Dynamic page loading failed' , err ) ; // eslint-disable-line no-console
5
+ }
6
+ function loadRoute ( cb ) {
7
+ return ( module ) => cb ( null , module . default ) ;
8
+ }
13
9
14
- export default routes ;
10
+ // React Router with code-splitting
11
+ // More Info: https://medium.com/modus-create-front-end-development/automatic-code-splitting-for-react-router-w-es6-imports-a0abdaa491e9
12
+ export default {
13
+ component : App ,
14
+ childRoutes : [
15
+ {
16
+ path : '/' ,
17
+ name : 'home' ,
18
+ getComponent ( nextState , cb ) {
19
+ System . import ( './modules/Post/pages/PostListPage/PostListPage' )
20
+ . then ( loadRoute ( cb ) )
21
+ . catch ( errorLoading ) ;
22
+ } ,
23
+ } ,
24
+ {
25
+ path : '/post/:slug' ,
26
+ name : 'post-detail' ,
27
+ getComponent ( nextState , cb ) {
28
+ System . import ( './modules/Post/pages/PostDetailPage/PostDetailPage' )
29
+ . then ( loadRoute ( cb ) )
30
+ . catch ( errorLoading ) ;
31
+ } ,
32
+ } ,
33
+ ] ,
34
+ } ;
Original file line number Diff line number Diff line change 2
2
if ( process . env . NODE_ENV === 'production' ) {
3
3
require ( './static/dist/server.bundle.js' ) ;
4
4
} else {
5
+ // System.import polyfill
6
+ if ( typeof System === 'undefined' ) {
7
+ System = {
8
+ import : function ( path ) {
9
+ return Promise . resolve ( require ( path ) ) ;
10
+ } ,
11
+ } ;
12
+ }
13
+
5
14
require ( 'babel-register' ) ;
6
15
require ( 'babel-polyfill' ) ;
7
16
require ( 'css-modules-require-hook' ) ;
Original file line number Diff line number Diff line change 59
59
"babel-preset-stage-0" : " ^6.5.0" ,
60
60
"babel-register" : " ^6.9.0" ,
61
61
"chai" : " ^3.5.0" ,
62
+ "chunk-manifest-webpack-plugin" : " 0.0.1" ,
62
63
"clean-css" : " ^3.4.13" ,
63
64
"css-loader" : " ^0.23.1" ,
64
65
"css-modules-require-hook" : " ^4.0.1" ,
70
71
"eslint-plugin-react" : " ^5.1.1" ,
71
72
"expect" : " ^1.20.1" ,
72
73
"extract-text-webpack-plugin" : " ^1.0.1" ,
74
+ "json-loader" : " ^0.5.4" ,
73
75
"mocha" : " ^2.5.3" ,
74
76
"nodemon" : " ^1.9.2" ,
75
77
"pre-commit" : " ^1.1.3" ,
82
84
"style-loader" : " ^0.13.1" ,
83
85
"supertest" : " ^1.2.0" ,
84
86
"webpack" : " ^2.1.0-beta.8" ,
85
- "webpack-dev-server" : " ^2.1.0-beta.0" ,
86
87
"webpack-dev-middleware" : " ^1.6.1" ,
87
- "webpack-hot-middleware" : " ^2.10.0"
88
+ "webpack-dev-server" : " ^2.1.0-beta.0" ,
89
+ "webpack-hot-middleware" : " ^2.10.0" ,
90
+ "webpack-manifest-plugin" : " ^1.0.1"
88
91
},
89
92
"engines" : {
90
93
"node" : " >=4"
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ import posts from './routes/post.routes';
33
33
import dummyData from './dummyData' ;
34
34
import serverConfig from './config' ;
35
35
36
+ // Import Manifests
37
+ const assetsManifest = require ( '../static/dist/manifest.json' ) ; // eslint-disable-line import/no-unresolved
38
+ const chunkManifest = require ( '../static/dist/chunk-manifest.json' ) ; // eslint-disable-line import/no-unresolved
39
+
36
40
// MongoDB Connection
37
41
mongoose . connect ( serverConfig . mongoURL , ( error ) => {
38
42
if ( error ) {
@@ -73,8 +77,12 @@ const renderFullPage = (html, initialState) => {
73
77
<div id="root">${ html } </div>
74
78
<script>
75
79
window.__INITIAL_STATE__ = ${ JSON . stringify ( initialState ) } ;
80
+ //<![CDATA[
81
+ window.webpackManifest = ${ JSON . stringify ( chunkManifest ) } ;
82
+ //]]>
76
83
</script>
77
- <script src="/dist/bundle.js"></script>
84
+ ${ process . env . NODE_ENV === 'production' ? `<script src='${ assetsManifest [ '/dist/vendor.js' ] } '></script>` : '' }
85
+ <script src="${ assetsManifest [ '/dist/app.js' ] } "></script>
78
86
</body>
79
87
</html>
80
88
` ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ module.exports = {
12
12
13
13
output : {
14
14
path : __dirname + '/dist/' ,
15
- filename : 'bundle .js' ,
15
+ filename : 'app .js' ,
16
16
publicPath : '/dist/' ,
17
17
} ,
18
18
Original file line number Diff line number Diff line change 1
1
var webpack = require ( 'webpack' ) ;
2
2
var ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
3
+ var ManifestPlugin = require ( 'webpack-manifest-plugin' ) ;
4
+ var ChunkManifestPlugin = require ( 'chunk-manifest-webpack-plugin' ) ;
3
5
4
6
module . exports = {
5
7
devtool : 'source-map' ,
6
8
7
- entry : __dirname + "/client/index.js" ,
9
+ entry : {
10
+ app : [
11
+ './client/index.js' ,
12
+ ] ,
13
+ vendor : [
14
+ 'react' ,
15
+ 'react-dom' ,
16
+ ]
17
+ } ,
8
18
9
19
output : {
10
20
path : __dirname + '/static/dist/' ,
11
- filename : 'bundle.js' ,
21
+ filename : '[name].[chunkhash].js' ,
22
+ publicPath : '/dist/' ,
12
23
} ,
13
24
14
25
resolve : {
@@ -35,6 +46,18 @@ module.exports = {
35
46
'NODE_ENV' : JSON . stringify ( 'production' ) ,
36
47
}
37
48
} ) ,
49
+ new webpack . optimize . CommonsChunkPlugin ( {
50
+ name : 'vendor' ,
51
+ minChunks : Infinity ,
52
+ filename : 'vendor.js'
53
+ } ) ,
54
+ new ManifestPlugin ( {
55
+ basePath : '/dist/'
56
+ } ) ,
57
+ new ChunkManifestPlugin ( {
58
+ filename : "chunk-manifest.json" ,
59
+ manifestVariable : "webpackManifest"
60
+ } ) ,
38
61
new webpack . optimize . UglifyJsPlugin ( {
39
62
compressor : {
40
63
warnings : false ,
Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ module.exports = {
40
40
] ,
41
41
} ,
42
42
} ,
43
+ {
44
+ test : / \. j s o n $ / ,
45
+ loader : 'json-loader' ,
46
+ } ,
43
47
] ,
44
48
} ,
45
49
} ;
You can’t perform that action at this time.
0 commit comments