|
| 1 | +# webpack/react-starter |
| 2 | + |
| 3 | +Starter template for react and webpack. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +* Compilation with webpack |
| 8 | +* React and jsx |
| 9 | +* Also includes reflux, but this can be easily replaced |
| 10 | +* Stylesheets can be CSS, LESS, SASS, Stylus or mixed |
| 11 | +* Embedded resources like images or fonts use DataUrls if appropriate |
| 12 | +* A simple flag loads a react component (and dependencies) on demand. |
| 13 | +* Development |
| 14 | + * Development server |
| 15 | + * Optionally Hot Module Replacement development server (LiveReload for Stylesheets and React components enabled) |
| 16 | + * Uses SourceUrl for performance, but you may switch to SourceMaps easily |
| 17 | +* Production |
| 18 | + * Server example for prerendering for React components |
| 19 | + * Long Term Cacheing through file hashes enabled |
| 20 | + * Generate separate css file to avoid FOUC |
| 21 | + * Minized CSS, HTML and javascript |
| 22 | +* Also supports coffee-script files if you are more a coffee-script guy. |
| 23 | +* You can also require markdown or text files for your content. |
| 24 | +* Just require the files... |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +Just clone this repo and change the `origin` git remote. |
| 29 | + |
| 30 | +``` text |
| 31 | +npm install |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | +## Development server |
| 36 | + |
| 37 | +``` text |
| 38 | +npm run dev-server |
| 39 | +http://localhost:2992/ |
| 40 | +``` |
| 41 | + |
| 42 | +The configuration is `webpack-dev-server.config.js`. |
| 43 | + |
| 44 | +Static HTML is served from `config/dev-server-public`. |
| 45 | + |
| 46 | +It automatically recompiles and refreshes the page when files are changed. |
| 47 | + |
| 48 | + |
| 49 | +## Hot Module Replacement development server |
| 50 | + |
| 51 | +``` text |
| 52 | +npm run dev-server |
| 53 | +http://localhost:2992/ |
| 54 | +``` |
| 55 | + |
| 56 | +The configuration is `webpack-hot-dev-server.config.js`. |
| 57 | + |
| 58 | +Static HTML is served from `config/dev-server-public`. |
| 59 | + |
| 60 | +It automatically recompiles when files are changed. When a hot-replacement-enabled file is changed (i. e. stylesheets or React components) the module is hot-replaced. If Hot Replacement is not possible the page is refreshed. |
| 61 | + |
| 62 | +Hot Module Replacement has a performance impact on compilation. |
| 63 | + |
| 64 | + |
| 65 | +## Production compilation and server |
| 66 | + |
| 67 | +``` text |
| 68 | +npm run build |
| 69 | +npm start |
| 70 | +http://localhost:8080/ |
| 71 | +``` |
| 72 | + |
| 73 | +The configuration is `webpack-production.config.js`. |
| 74 | + |
| 75 | +The server is at `lib/server.js` |
| 76 | + |
| 77 | +The production setting builds two configurations: one for the client (`build/public`) and one for the serverside prerendering (`build/prerender`). |
| 78 | + |
| 79 | +> WIP: Serverside data fetching and embedding data into served HTML. |
| 80 | +
|
| 81 | + |
| 82 | +## Build visualisation |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +## Loaders and file types |
| 88 | + |
| 89 | +Many file types are preconfigured, but not every loader is installed. If you get an error like `Cannot find module "xxx-loader"`, you'll need to install the loader with `npm install xxx-loader --save` and restart the compilation. |
| 90 | + |
| 91 | + |
| 92 | +## Common changes to the configuration |
| 93 | + |
| 94 | +### Add more entry points |
| 95 | + |
| 96 | +(for a multi page app) |
| 97 | + |
| 98 | +1. Add an entry point to `make-webpack-config.js` (`var entry`). |
| 99 | +2. Add a new top-level react component in `app`. |
| 100 | +3. (Optional) Enable `commonsChunk` in `webpack-production.config.js`. |
| 101 | +4. Add a new HTML file in `config/dev-server-public` that references the new output file. |
| 102 | +5. Restart compilation. |
| 103 | + |
| 104 | +### Switch devtool to SourceMaps |
| 105 | + |
| 106 | +Change `devtool` property in `webpack-dev-server.config.js` and `webpack-hot-dev-server.config.js` to `"source-map"` (better module names) or `"eval-source-map"` (faster compilation). |
| 107 | + |
| 108 | +SourceMaps have a performance impact on compilation. |
| 109 | + |
| 110 | +### Enable SourceMaps in production |
| 111 | + |
| 112 | +1. Uncomment the `devtool` line in `webpack-production.config.js`. |
| 113 | +2. Make sure that the folder `build\public\debugging` is access controlled, i. e. by password. |
| 114 | + |
| 115 | +SourceMaps have a performance impact on compilation. |
| 116 | + |
| 117 | +SourceMaps contains your unminimized source code, so you need to restrict access to `build\public\debugging`. |
| 118 | + |
| 119 | + |
| 120 | +## License |
| 121 | + |
| 122 | +Copyright (c) 2012-2014 Tobias Koppers [](https://www.gittip.com/sokra/) |
| 123 | + |
| 124 | +MIT (http://www.opensource.org/licenses/mit-license.php) |
0 commit comments