| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,12 @@ | |||
| 5 | 5 | "react" | |
| 6 | 6 | ], | |
| 7 | 7 | "plugins": [ | |
| 8 | + ["universal-import", { | ||
| 9 | + "babelServer": true | ||
| 10 | + }], | ||
| 8 | 11 | "transform-runtime", | |
| 9 | 12 | "transform-decorators-legacy", | |
| 10 | - "babel-plugin-transform-class-properties", | ||
| 11 | - "dual-import" | ||
| 13 | + "babel-plugin-transform-class-properties" | ||
| 12 | 14 | ], | |
| 13 | 15 | "sourceMaps": true | |
| 14 | 16 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,11 +7,6 @@ | |||
| 7 | 7 | "name": "Launch via Babel", | |
| 8 | 8 | "program": "${workspaceRoot}/src/server/server.js", | |
| 9 | 9 | "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node", | |
| 10 | - "args": [ | ||
| 11 | - "--plugins", | ||
| 12 | - "system-import-transformer", | ||
| 13 | - "--" | ||
| 14 | - ], | ||
| 15 | 10 | "env": { | |
| 16 | 11 | "NODE_ENV": "development", | |
| 17 | 12 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,22 @@ | |||
| 1 | 1 | import React from 'react'; | |
| 2 | - import { BrowserRouter } from 'react-router-dom'; | ||
| 3 | - import { renderRoutes } from 'react-router-config'; | ||
| 4 | - import routers from './routers'; | ||
| 2 | + import { AsyncHome, AsyncProfile } from './routers'; | ||
| 3 | + import { Route, Link } from 'react-router-dom' | ||
| 5 | 4 | ||
| 6 | - const Main = () => ( | ||
| 7 | - <BrowserRouter> | ||
| 8 | - {renderRoutes(routers)} | ||
| 9 | - </BrowserRouter> | ||
| 10 | - ); | ||
| 5 | + export default class App extends React.Component { | ||
| 6 | + render() { | ||
| 7 | + return ( | ||
| 8 | + <div> | ||
| 9 | + <div> | ||
| 10 | + <ul> | ||
| 11 | + <li><Link to={'/'}>Home</Link></li> | ||
| 12 | + <li><Link to={'/profile'}>profile</Link></li> | ||
| 13 | + </ul> | ||
| 14 | + <Route exact path={'/profile'} component={AsyncProfile} /> | ||
| 15 | + <Route exact path={'/'} component={AsyncHome} /> | ||
| 16 | + </div> | ||
| 17 | + </div> | ||
| 18 | + ) | ||
| 19 | + } | ||
| 20 | + } | ||
| 11 | 21 | ||
| 12 | - export default Main; | ||
| 22 | + // export default Main; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,18 @@ | |||
| 1 | 1 | /* eslint-env browser */ | |
| 2 | - | ||
| 3 | - import App from './app'; | ||
| 4 | - import configureStore from './store'; | ||
| 5 | 2 | import React from 'react'; | |
| 6 | 3 | import ReactDOM from 'react-dom'; | |
| 7 | 4 | import { Provider } from 'react-redux'; | |
| 5 | + import { BrowserRouter } from 'react-router-dom' | ||
| 6 | + import configureStore from './store'; | ||
| 7 | + import App from './app'; | ||
| 8 | 8 | ||
| 9 | 9 | const store = configureStore(window.initialState); | |
| 10 | 10 | ||
| 11 | - window.dev = { store }; | ||
| 12 | - | ||
| 13 | 11 | ReactDOM.render( | |
| 14 | 12 | <Provider store={store}> | |
| 15 | - <App /> | ||
| 13 | + <BrowserRouter> | ||
| 14 | + <App /> | ||
| 15 | + </BrowserRouter> | ||
| 16 | 16 | </Provider>, | |
| 17 | 17 | document.getElementById('app') | |
| 18 | 18 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,32 +3,32 @@ import React from 'react'; | |||
| 3 | 3 | import universal from 'react-universal-component' | |
| 4 | 4 | import AppRoot from './container/root'; | |
| 5 | 5 | ||
| 6 | - const AsyncHome = universal(() => import('./container/home'), { | ||
| 6 | + export const AsyncHome = universal(() => import('./container/home'), { | ||
| 7 | 7 | resolve: () => require.resolveWeak('./container/home'), | |
| 8 | 8 | chunkName: 'container/home', | |
| 9 | 9 | minDelay: 500, | |
| 10 | 10 | }); | |
| 11 | 11 | ||
| 12 | - const AsyncProfile = universal(() => import('./container/profile'), { | ||
| 12 | + export const AsyncProfile = universal(() => import('./container/profile'), { | ||
| 13 | 13 | resolve: () => require.resolveWeak('./container/profile'), | |
| 14 | 14 | chunkName: 'container/profile', | |
| 15 | 15 | minDelay: 500, | |
| 16 | 16 | }); | |
| 17 | 17 | ||
| 18 | - const routes = [ | ||
| 19 | - { | ||
| 20 | - path: '/', | ||
| 21 | - exact: true, | ||
| 22 | - component: AppRoot | ||
| 23 | - }, | ||
| 24 | - { | ||
| 25 | - path: '/home', | ||
| 26 | - component: AsyncHome, | ||
| 27 | - }, | ||
| 28 | - { | ||
| 29 | - path: '/profile', | ||
| 30 | - component: AsyncProfile | ||
| 31 | - } | ||
| 32 | - ]; | ||
| 18 | + // const routes = [ | ||
| 19 | + // { | ||
| 20 | + // path: '/', | ||
| 21 | + // exact: true, | ||
| 22 | + // component: AppRoot | ||
| 23 | + // }, | ||
| 24 | + // { | ||
| 25 | + // path: '/home', | ||
| 26 | + // component: AsyncHome, | ||
| 27 | + // }, | ||
| 28 | + // { | ||
| 29 | + // path: '/profile', | ||
| 30 | + // component: AsyncProfile | ||
| 31 | + // } | ||
| 32 | + // ]; | ||
| 33 | 33 | ||
| 34 | - export default routes; | ||
| 34 | + // export default routes; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + const rimraf = require('rimraf'); | ||
| 2 | + const path = require('path'); | ||
| 3 | + | ||
| 4 | + console.log(path.resolve('dist'), process.cwd()) | ||
| 5 | + | ||
| 6 | + const distPath = path.join(__dirname, '../../dist'); | ||
| 7 | + console.log(distPath) | ||
| 8 | + rimraf.sync(`${distPath}/*`); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,11 @@ import flushChunks from 'webpack-flush-chunks' | |||
| 7 | 7 | import { renderRoutes, matchRoutes } from 'react-router-config'; | |
| 8 | 8 | import { StaticRouter } from 'react-router-dom'; | |
| 9 | 9 | // user config | |
| 10 | - import routers from '../../client/routers'; | ||
| 10 | + // import routers from '../../client/routers'; | ||
| 11 | 11 | import initialStore from '../../client/store'; | |
| 12 | 12 | // template function return string | |
| 13 | 13 | import { tmpl } from './tmpl'; | |
| 14 | + import App from '../../client/app'; | ||
| 14 | 15 | ||
| 15 | 16 | function render(clientStats) { | |
| 16 | 17 | const chunkNames = flushChunkNames(); | |
@@ -19,23 +20,23 @@ function render(clientStats) { | |||
| 19 | 20 | return function (req, res, next) { | |
| 20 | 21 | const store = initialStore(); | |
| 21 | 22 | const { dispatch } = store; | |
| 22 | - const branch = matchRoutes(routers, req.url); | ||
| 23 | - const styleObj = {}; | ||
| 24 | - const promiseList = branch.map(({ route }) => { | ||
| 25 | - const { component } = route; | ||
| 26 | - return route.component.getInitialData ? route.component.getInitialData(dispatch) : Promise.resolve(); | ||
| 27 | - }); | ||
| 23 | + // const branch = matchRoutes(routers, req.url); | ||
| 24 | + // const styleObj = {}; | ||
| 25 | + // const promiseList = branch.map(({ route }) => { | ||
| 26 | + // const { component } = route; | ||
| 27 | + // return route.component.getInitialData ? route.component.getInitialData(dispatch) : Promise.resolve(); | ||
| 28 | + // }); | ||
| 28 | 29 | ||
| 29 | - Promise.all(promiseList) | ||
| 30 | - .then(v => { | ||
| 30 | + // Promise.all(promiseList) | ||
| 31 | + // .then(v => { | ||
| 31 | 32 | const content = renderToString( | |
| 32 | 33 | <Provider store={store}> | |
| 33 | 34 | <StaticRouter location={req.url} context={{}}> | |
| 34 | - {renderRoutes(routers)} | ||
| 35 | + <App /> | ||
| 35 | 36 | </StaticRouter> | |
| 36 | 37 | </Provider> | |
| 37 | 38 | ); | |
| 38 | - console.log(styles.toString()) | ||
| 39 | + console.log(content) | ||
| 39 | 40 | res.send( | |
| 40 | 41 | `<!doctype html> | |
| 41 | 42 | <html> | |
@@ -59,11 +60,11 @@ function render(clientStats) { | |||
| 59 | 60 | // initialCss: styleObj | |
| 60 | 61 | // }) | |
| 61 | 62 | // ); | |
| 62 | - }) | ||
| 63 | - .catch(err => { | ||
| 64 | - console.log(err); | ||
| 65 | - res.end("didn\'t match any route. Check your url"); | ||
| 66 | - }); | ||
| 63 | + // }) | ||
| 64 | + // .catch(err => { | ||
| 65 | + // console.log(err); | ||
| 66 | + // res.end("didn\'t match any route. Check your url"); | ||
| 67 | + // }); | ||
| 67 | 68 | } | |
| 68 | 69 | } | |
| 69 | 70 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,20 @@ const config = { | |||
| 26 | 26 | test: /jsx?/, | |
| 27 | 27 | use: { | |
| 28 | 28 | loader: 'babel-loader', | |
| 29 | + options: { | ||
| 30 | + presets: [ | ||
| 31 | + "stage-0", | ||
| 32 | + "es2015", | ||
| 33 | + "react" | ||
| 34 | + ], | ||
| 35 | + plugins: [ | ||
| 36 | + "transform-runtime", | ||
| 37 | + "transform-decorators-legacy", | ||
| 38 | + "babel-plugin-transform-class-properties", | ||
| 39 | + "universal-import" | ||
| 40 | + ], | ||
| 41 | + babelrc: false | ||
| 42 | + } | ||
| 29 | 43 | }, | |
| 30 | 44 | exclude: /node_modules/, | |
| 31 | 45 | }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments