The Wonderful World of Webpack
jackhiston.com
jackhiston.com
I think Webpack is a step in the correct direction, but web bundlers are still in need of improving.
Maybe I was doing it wrong but for a previous project I was using SystemJS for module loading + bundling and Gulp for SASS + TypeScript compilation and livereload. I've replaced all of this with a much simpler (before I had too many differences between development and production builds) Webpack configuration that does everything. Setting up both configurations drove me up the wall with the usual array of "module not found" and "file not found" problems you have to persist with but the Webpack setup feels more robust now that it's working.
Probably not an easy problem, but it would be amazing if build tools by default gave you a lot of help with debugging errors e.g. "module a/b/c not found, did you mean ../a/b/c?".
https://github.com/saguijs/sagui
https://github.com/mozilla-neutrino/neutrino-dev
https://github.com/facebookincubator/create-react-app
They help frame this domain's perspective on the timeless tension between usability and flexibility - ie am I prepared to sacrifice some configuration options in return for being able to get quickly setup?
Clearly the answer in a lot of cases is going to be 'no', but nevertheless seeing how difficult it can be to find that sweet spot between usability and flexibility might help one better appreciate the value returned by those difficulties.
Personally, I've found the commitment to stick to the conventions enforced by Create React App to have been largely beneficial (at least so far (in one project)). And I've been surprised how willing and able I am to creatively work within those limitations.
The best part about create-react-app is the `eject` option. So you never have to ask that question. You can just get going with the defaults, then 'eject' your config files to tweak once you uncover your specific needs.
I am convinced this 'no lock-in' approach is the way to go for scaffolding builders and frameworks in general.
Best part or necessary evil? I'm glad it exists, but ultimately you lose a lot of the benefits of create-react-app (seamless updates to react-scripts, e.g. the move from Webpack 1 to 2) as soon as you eject, which is why it is somewhat discouraged, and why some people have built projects that allow you more config overrides without ejecting.
You don't really need to spend too much time configuring Webpack if you're just trying to bundle a bunch of JS files together. I.e, if you don't need the fancy loaders and plugins and just want an optimized JS bundle, the instructions on this page are all you need: https://webpack.js.org/api/cli/ (see section titled "Usage Without Config File")
But of course, you don't want just that. You want support for ES6, JSX, bundling and optimizing CSS, autoprefixing, bundle splitting, building SVG sprite sheets, etc. etc. At that point you just have to deal with the complexity.
> Personally, I've found the commitment to stick to the conventions enforced by Create React App to have been largely beneficial (at least so far (in one project)). And I've been surprised how willing and able I am to creatively work within those limitations.
I feel the same way. I no longer configure my build system from scratch. I try to work with create-react-app's defaults for as long as possible, and eject if I can't coax it into doing something I need. It's no different from letting XCode or Visual Studio autogenerate a project for you and customizing it as you go along.
At the end of the day, I'd rather write code than configure build systems. But sadly, they're a necessary evil no matter what tech stack you work with. I personally feel that it's not worth spending time learning them deeply, but I'm prepared to pull up that Webpack manual one day because I know I'm definitely going to need it at some point.
That's why I made a boiler plate project with React SSR, TypeScript, and Webpack
Being able to just start writing code without spending forever setting up the perfect environment is hugely liberating. I'd encourage everyone to find good boilerplates for what they want to do (or put together their own if nothing else fits)
Here are the two boilerplates mentioned:
https://packagejason.herokuapp.com/krakenjs/grumbler
https://packagejason.herokuapp.com/styfle/react-server-examp...
and you can search others to your fancy.
Make is truly a timeless tool. Parallel, incremental, and declarative; it's a well architected tool based on correct principles. Everything else -- Ant, Maven, Grunt, Gulp -- are diappointments by comparison. Unfortunately, however, make wasn't made to compose well; you'll rarely see people (including me) publishing and re-using rules.
If you want a general-purpose composable non-sucky build tool, check out Google Bazel (in beta): https://bazel.build/
Blog post from Google Angular engineer, including thoughts on make and Bazel for front-end builds: https://medium.com/@Jakeherringbone/building-angular-apps-at...
I'm not saying Gulp, Grunt or Webpack will suit your needs but I find Makefiles quickly become very unreadable and hard to debug. Its syntax for loops, conditions and arithmetic is awkward and hard to remember and the behaviour of variables is confusing. At least with the others the syntax is decent and there's tons of plugins for common tasks.
Why would Gulp for example not suit your use case?
PMake (aka BSD Make) is actually fairly good in this regard- allowing for include libraries (so long as namespaces don't collide). Unfortunately it is not so well known...
My intuition is that this is because we are using a declarative programming model: a config file, rather than code.
I don't really understand why we would use, say, Ruby to encode a web server, and then use JSON to encode the build process. We choose our programming languages very carefully for their ability to express powerful control structures, ease of maintenance, debuggability.... and then we use a brittle, underspecified language of flags, nested keys, and filesystem tests and side effects to program our build system... Why?
Can someone who believes in this declarative config build system explain why, in the abstract, it's a good fit for build processes, when we'd never choose a language like that for our actual codebase?
I'm influenced here by Jonathan Blow, who designed into Jai the ability to run arbitrary Jai code during the build process, for this exact reason.
Configuring Webpack to do this was one of the hardest things I've ever done. :D
And Google has always been a heavy user of course.
Closure Compiler is preternaturally good at dead code removal, inlining, minification. But you have to use advanced optimization mode, and write JS amenable to its static analysis. If you're willing to put in that work, you'll get fantastic minification. If you're not, you should just find another tool.
Scala.js includes Closure Compiler adv optimizations right in the standard workflow, so it's a good bet any Scala.js project will be using it.
Sadly, I haven't found a way around the dependency yet.
Most of my projects don’t need the scalability of Facebook or Instagram, so I can do without some of Webpacks more nuanced features. My entire dev/build/deploy cycle is just a couple npm scripts.[2]
1 - https://github.com/mattdesl/budo
2 - https://github.com/Jam3/360-image-viewer/blob/master/package...
Smaller, type-checked build files, even has a native packager plugin for building RPMs... really very nice.
What?! Image, crop and greyscale? That doesn't sound like a job for a bundler. Is this sarcasm?