This is a very simple, boiler-plate, client-side only application using React, Webpack, and Babel.
TODO link to gh-pages
A few different scripts have been provided to see the different possibilities with babel and webpack.
npm run babel
This command will just run the babel transpilation on the two *.jsx source files in /src, and output the transpiled versions to the corresponding location in /lib.
This will allow you to see what the output of babel looks like.
Additionally, these files could then be required via the <script /> tag in an HTML document and, as long as all of their dependencies were present as well (react, react-dom, etc.), these would be able to be executed in any modern browser.
-
npm run buildThis executes the following script:
node ./node_modules/.bin/webpack
This tells webpack to bundle the files. Webpack by default will look for a
webpack.config...file in the current directory, so it findswebpack.config.babel.jsand uses that.The
.babel.json the end gets the code transpiled using our babel configuration first, before it is executed, so we can use ES2015 language features in our webpack configuration.The configuration is thoroughly documented with comments in the file.
The result of running this command is three new or updated files in the
/distdirectory:bundle.js: a bundle containing a transpiled/src/index.jsx, along with all ofindex.jsx's dependencies. This includesreact,react-dom,/src/components/Hello, and any dependencies that those files have.index.html: becauseindex.htmlis listed as an entry point in our webpack configuration and we use thehtml-loader, the file gets copied from/srcto/distfor us. At this point, we are not performing any transpilation or other transformations of this file, just copying it over.
-
npm run devThis executes the following script:
node ./node_modules/.bin/webpack -d --watch
This tells webpack to bundle the files, just as it did with the
npm run buildscript previously discussed.The difference is that webpack will then also watch for further changes. Whenever a change is made, that part of the code is rebundled automatically, so you always have an up-to-date bundle.
This requires a refresh to view the updated output in your browser.
Additionally, the
-doption is the development shortcut. Among other things, this causes webpack to emit one additional file:bundle.js.map: map files that make debugging our bundle possible using something like Chrome's developer tools. Map files enable the browser to trace minified code back to the actual code that the developer wrote.
Coming soon
Please do! Use GitHub to fork this project, make and commit your changes, and then submit a new pull request.
We're just using the /dist directory on the gh-pages branch to show people what the result of the included code is.
After making your changes, run:
npm run build
# !! commit your changes here !!
git subtree push --prefix dist origin gh-pagesThis updates the bundled code in the /dist directory, then you commit the updated source, then push the /dist directory to the root of the gh-pages branch.
The biggest downside to this is having bundled code in our repo, but we'll live.
- Appendix A of Pro React: Webpack for React