react16 + react-router4 + webpack4 + mobx + SSR 服务端渲染 + HMR 热更新 + 代码分割
324
react16 + react-router4 + webpack4 + mobx + SSR 服务端渲染 + HMR 热更新 + 代码分割
yarnnpm run dev-all
同时启动客户端&服务端开发模式
服务端运行在 3000 端口,获取的 js,css 资源来自 3001
实现统一的 hot reload 开发
ps. 由于采用了 css-hot-loader , 所以开发模式下服务端渲染后页面会闪一下,生产模式不会有这个问题
npm run dev
只客户端渲染 启动在 3001
已支持 hot reload 改动即时生效
npm run dev-ssr
只服务端渲染 启动在 http://localhost:3000/
采用 webpack watch 即时编译 client & server 代码,刷新生效
npm run buildnode server.js 或者 pm2react routerreact-loadablewebpack-dev-middleware
webpack-hot-middleware
react-hot-loader
webpack -w
2 configs, 2 ports, 2 webpack instances, both watching and hot reloading the same filesystem, in parallel during development and a little webpack.output.publicPath magic.
In development mode (razzle start), Razzle bundles both your client and server code using two different webpack instances running with Hot Module Replacement in parallel. While your server is bundled and run on whatever port you specify in src/index.js (3000 is the default), the client bundle (i.e. entry point at src/client.js) is served via webpack-dev-server on a different port (3001 by default) with its publicPath explicitly set to localhost:3001 (and not / like many other setups do). Then the server's html template just points to the absolute url of the client JS: localhost:3001/static/js/client.js. Since both webpack instances watch the same files, whenever you make edits, they hot reload at exactly the same time. Best of all, because they use the same code, the same webpack loaders, and the same babel transformations, you never run into a React checksum mismatch error.
Content type
Image
Digest
Size
48.4 MB
Last updated
almost 8 years ago
docker pull yuxizhe/react-ssr-start