Tips and tricks in using Webpack
github.com
github.com
Hopefully including more real-world cases than greenfield clean code projects: I want something like "start using webpack in an already started project that mixes jQuery & Backbone, React and some Polymer on a few pages, and a home-brewed-framework legacy portion" and maybe also has a few "isomorphic modules" (ya know, the kind of code that can run both in browser and in backend nodejs depending on context, but it "home made", not based on some nice magic sauce like Meteor). Because this is what you see in real world projects and the first questions when I tocuhed webpack were more along the lines of "how tf do I mix this old-school browsers global script + this commonjs/require one + this idiosincratic node-browser-isomorphic one" and "how to I tweak minification rules for one file only to prevent weird code breaks from variable renames"...
It's amazing how much modern js learning resources assume you already know! And how plain/normal they expect your project to be when in real life you're always seeing a mystic-quantum-chemistry-frankestein-puppy-hybrid thing :)
It sounds like you were looking for a tool more akin to UglifyJS or google's closure compiler, which(as far as I know) take a single file and analyze it, and then try to output "better" code equivalent to it.
Webpack tries to solve a different problem - from a bunch of scattered lego blocks you define an "application"(by defining dependencies), and have webpack bundle it together for you.
If you have a specific use case and mangled array of libraries, frameworks and build systems, you can't expect it to be handled automatically by a magic new tool.
[0] https://github.com/markerikson/react-redux-links
[1] https://github.com/markerikson/react-redux-links/blob/master...
[2] https://github.com/markerikson/react-redux-links/blob/master...
First, the custom js loading was buggy and inefficient so we moved it to requirejs. Then we wanted everything to be bundled into a single file so we figured out r.js. r.js was really slow and we wanted pre-compiled handlebars templates so we moved over to webpack. Now, we keep accidentally writing es2015 and breaking IE11 so it'll probably be time to introduce babel at some point.
It was really no different than any other major refactoring. Fix up the code and then chisel away the error messages one at a time.
* Allocate training time for all team members to go through some e-learning courses / tutorials about Webpack (Frontend Masters, egghead.io, etc) and UMD (assorted tutorials / blog posts)
* After much hand-wringing we decided that for our situation converting our all-over-the-place JS codebase to UMDs with global fallbacks was the most flexible approach. This allows us to use the same code both in Webpack bundles and in our existing litany of <script> tags. Introducing Webpack has forced us to pay down a lot of technical debt during the process, something that has been years overdue but had to get done eventually. It's been frustrating having to clean up the mess made by developers who no longer work here but ¯\_(ツ)_/¯
* Created a long-running feature branch where we added Node.js and Webpack dependencies to our existing Java / Spring / Maven project
* As internal libraries are converted to UMD, merge them into the feature branch and add them to the appropriate Webpack bundle. Any 3rd party JS libraries that are available via npm have been removed from our codebase and are now pulled in as dependencies via package.json
* Put everything behind feature toggles
* Experiment with our CD / CI pipelines using the Webpack feature branch to make sure we can reliably break the Maven build when something goes wrong with Webpack / Node.js, generate fresh bundles for hot / partial deploys, and get things deployed to an app server in one of our dev environments without any issues
* Do demos every 2-3 weeks for both our team and other teams / managers to show progress, share lessons learned, etc
All of this has unfolded along with our regular workload over the last 3 months or so. We've taken a measured approach with small steps along the way and it's worked out well.
A lot of people are off for the holidays so my guess is we'll start introducing Webpack bundles into production sometime in mid-late January.
As an added benefit, this project has been used to establish a bit of a beachhead with respect to introducing Node.js to our various codebases so we can start doing automated testing, modern JS dependency management, code linting / style enforcement, and providing better developer tools to the team(s) that write JS / CSS / etc.
The "vendor" and module splitting are good examples of this. Or, in this example, using "process.env.NODE_ENV" makes a lot of sense if you use Heroku, but is more cosmetic if you control the entire build chain.
We even have a new docs page where hopefully _most_ of the things on this document are (if not should be) covered.
webpack.js.org webpack.js.org/concepts
~Sean + webpack Team
I really like how straight forward Browserify is. Likely this is because I am quite accustomed to Unix shell tools and makefiles (I actually use Ninja [1] with ninja-build-gen [2] for a few of my Javascript projects) but Webpack's hot-reloading would be really nice to have.
I do think it would suffice if Browserify was a bit more performant so I don't have to wait for it after making a change. I keep meaning to try Rollup to see if it will give me any advantages in that regard.
I think one of Webpack's benefits is that this stuff is all bundled with it, so everyone's using it but with browserify you need to go out and find these solutions yourself
Ah, it never even occurred to me to look for something like browserify-hmr, will definitely try this out!
const DEBUG = process.env.NODE_ENV !== 'production'
module.exports = {
debug: DEBUG ? true : false