https://github.com/theasta/paris-webpack-react.git
cd paris-webpack-react
npm install
- Build and start watching files with Webpack:
npm run webpack-dev
- Spin up the node.js backend server:
node server/server-dev.js
- Go to http://localhost:3000
- Open homepage.jsx and replace
iconEiffelTower
in<HeadingItem title="Monuments" icon={iconEiffelTower}/>
(line 21) byiconNotreDame
- In your terminal, you can see the homepage bundle was re-emitted. Nothing changed for the other ones.
- Reload the homepage. The second eiffel tower icon has been replaced by a Notre Dame icon.
Exit the webpack task
app.js 1884285 0 [emitted] app homepage.js 1132531 1 [emitted] homepage plans.js 1124744 2 [emitted] plans login.js 1124834 3 [emitted] login
npm run webpack-stats
- Check at the root of the repository. A stats.json file has been generated.
- Open http://webpack.github.io/analyse/ , click on choose file and browse to the stats.json file
- Go to the hints section. You can see a lot of files are shared across the 4 bundles. You can also see that the Signup.jsx is shared by only 2 bundles.
- Open webpack-dev.config.js
- Set the commonsChunk property to true
npm run webpack-dev
A new bundle has been created: common.js. It contains all the files common to the 4 bundles
- Edit the webpack task
- Uncomment the commonschunkMin attribute in webpack-dev.config.js. It tells webpack that every module that is shared by at least 2 bundles has to be sent to the common bundle.
npm run webpack-dev
The plans and homepage bundles are now smaller. The Signup.jsx has been moved to common.js
Exit the webpack task
Exit the webpack-dev-task
- Open webpack-dev.config.js
- Set the CODE_SPLITTING to true. This will set a variable CODE_SPLITTING that acts like a feature flag. This variable is used in routes.jsx
npm run webpack-dev
- Open Chrome's network panel
- Go to http://localhost:3000/app. Two javascript files are loaded: common.js and app.js
- Click on the Analytics button in the navigation bar at the top.
- The analytics bundle (section_0.js) is loaded asynchronously and appears in the network panel.
Exit the webpack-dev task and spin down the node.js backend server.
Let's pretend we are releasing to production and uploading our static assets to a CDN
npm run build
- Go to http://localhost:3000
- Open the network panel and reload the page
- All the assets are versioned: css, js and even images and fonts. Images referenced in CSS have also been versioned.
Note: The publicPath option in the webpack configuration lets you set the path to your CDN.
Exit the npm task
npm run webpack-dev-server
node server/server-dev-server.js
- Go to http://localhost:3000
- Open homepage.jsx, replace "Best of Paris" by "Best of Paname". Save the file. On save, the browser reloads automatically the homepage and your change is applied.
- Go to http://localhost:3000/app
- Open AttractionListItem.jsx and replace "" by "". This time, on save, your change is reflected right away without a page reload.
- It also works with any file that is required with Webpack. Make a change to AttractionListItem.css and it will be applied right away too.