chore(build): Move to webpack for bundling/building #103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #88.
Included in this PR:
npm start
script kicks offwebpack-dev-server
with livereload and a non-minified build with SourceMaps.package.json
dependencies intodependencies
anddevDependencies
npm build
bundles, minifies and hashes the application for production and outputs to thebuild
directorynpm server
will serve locally whatever is in thebuild
directory (for testing production build locally)Notes:
require
in favor of ES6-styleimport
. For templates see: Importing files other than TS modules microsoft/TypeScript#2709 and Support shorthand ambient module declarations and wildcard chars in module names microsoft/TypeScript#6615src/
instead ofsrc/main
), but that's up to you. Left it alone because I didn't want this PR to be more disruptive than necessary.Size of the production build:
The fully minified
vendor.js
is ~800kb. That seems large to me and I wasn't able to make it any smaller with the experimentation I did.The idea behind splitting the main.js and vendor.js files is that your vendored dependencies are not changing as often as your application files are. With the bundled files hashed, your users will have the larger vendor file cached locally and they won't need to pull it down again with an application update if the dependencies don't change. So even though it's a larger file, hopefully it's being fetched infrequently.
The alternative would be to do away with the
vendor.ts
entry point and just let everything bundle into amain.ts
. That said, even when I experimented with pullingimports
out ofvendor.ts
(like say Angular 2) and letting the application dependencies pull them in as needed, it just shifted a similar size of the bundle from vendor to main. Webpack 2 is supposed to be including some form of tree-shaking during minification so that might help, but it's still in beta at the moment.I added an
npm stats
script that will do a production build and spit out astats.json
for use at http://webpack.github.io/analyse/ to help figure out where all module dependencies are coming from if you want to look into it in more detail.Webpack Information Sources:
I relied heavily on http://survivejs.com/webpack_react/building_kanban and https://github.com/AngularClass/angular2-webpack-starter to get to this point. Angular2 with TypeScript is in a weird spot for Webpack right now, requiring a bunch of polyfills and workarounds that I stole from angular2-webpack-starter (but which seems entirely too complex to just use outright). The SurviveJS Webpack React example is much simpler for understanding the core concepts and I used their approach for building a common
webpack.config.js
that was sensitive to environment which I thought was cleaner than duplicating things in two separate configs.Let me know if you have any questions. Won't have much time over the next few weeks to keep working on this but I think this is a good starting point that you can continue to refine or change as you go.
Cheers!