Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle dependencies and code using Webpack #869

Closed
SunburnedGoose opened this issue Sep 8, 2016 · 17 comments
Closed

Bundle dependencies and code using Webpack #869

SunburnedGoose opened this issue Sep 8, 2016 · 17 comments

Comments

@SunburnedGoose
Copy link
Member

A LONG TERM goal for DIM was to start bundling our dependencies. This has come consequence that needs to be considered.

  1. Bundle source code
  2. Bundle vendors
  3. Watch source and rebundle
  4. Adding new files
  5. Adding new vendors
  6. Updating Index File with latest bundle hashed filenames.
@bhollis
Copy link
Contributor

bhollis commented Sep 9, 2016

Definitely. I have something half-built in a branch but I haven't had a chance to get back to it.

@bhollis bhollis self-assigned this Nov 7, 2016
@SunburnedGoose
Copy link
Member Author

Couple issues remain.

  • Add Hotkeys CSS
  • Copy zip.js files during install to remove them from Bower
  • Import font-awesome using webpack to remove them from Bower

Once these tasks are done, bower can be removed from DIM. I've added the appropriate commands to build the generated file to npm on install.

We're at the point now where we can consider bringing in the scripts into webpack and chunking the export with vendor/app files, setting up a watcher to recompile the app files when they change, and building with ES6/Babel. I'm not sure we should refactor what we have to ES6...

@joshhunt
Copy link
Contributor

👋 Happy to help out where I can! Webpack's the sort of thing I guess where its very easy to step on other people's toes and waste effort, so I'm happy to do as much (or little) to move this forward, given some direction.

@bhollis
Copy link
Contributor

bhollis commented Dec 29, 2016 via email

@bhollis
Copy link
Contributor

bhollis commented Dec 29, 2016 via email

@SunburnedGoose
Copy link
Member Author

@joshhunt What should we be looking out for? We're incrementally updating our build process so atm all of our code is ES5.

@joshhunt
Copy link
Contributor

joshhunt commented Dec 30, 2016

First up, Webpack 2 is in a pretty stable now (I think its in RC or something, I've been using a much earlier beta in a project for a while and its fine), so I would recommend we go with that from the start. There's not too much different (in terms of config and using it) from Webpack 1, so it should be fine. Docs are on this new site.

Personally, I think the priority is to bundle everything together first, building your dependency graph using imports/requires. This would require 'minimal' code changes to the application, but we would have to go through and make sure that every source file and external dependency is 'required' from some place.

There's a bunch of ways to architect this for an Angular app (or so I've read, I don't really use Angular all that much), but I think the best way for now would be to treat... dimApp.module.js as the entry point and add a whole bunch of imports at the top:

import "scripts/dimApp.config";
import "scripts/dimApp.i18n";
import "scripts/services/dimActionQueue.factory";
import "scripts/services/dimBungieService.factory";
import "scripts/services/dimDefinitions.factory";
import "scripts/services/dimManifestService.factory";

angular.module('dimApp', [
    'ui.router',
    'timer',
    ...
])

We would also need to import at least Angular at the top of every file (that uses it). Technically you could use webpack.ProvidePlugin() to make it 'global' to every module, but I'm not really a fan of that.

Adding a babel config to pop in ES6+ syntax as we go would also be a great idea. babel-preset-env is all the rage these days as a good preset to use.

And then I guess a switch to generate 'production' and 'development' builds (to minify) would also be recommended.

This might sound like a lot, but I think it's fairly straightforward. That should be the target for the 'first release' of webpack. After that we can work on reaping the benefits like seperate vendor builds, ng-annotate, directive templates, etc.

I'm happy to build on what's been done here and take a stab at the above, as long as I don't step on anyone toes. I should be able to get something solid done today, once I finish the raid 😉

@joshhunt
Copy link
Contributor

Oh, few other random points:

  • WebpackDevServer during development to serve out and watch for changes in files.
  • Not 100% sure on the best way to get the build to work nicely for both a Chrome Extension AND a published website (in terms of asset URLs), but it shouldn't be a showstopper.
  • Using [hash] in the output filename, together with HtmlWebpackPlugin is a great way to hash the files and update the index.html file to reflect the URLs
  • CSS-Loader + ExtractTextPlugin should be good to handle the CSS with webpack. This should also sort out the Hotkey CSS and Font Awesome stuff
  • Should be able to move most of the deps to package.json, and make sure the the build artefacts aren't committed to git.

@SunburnedGoose
Copy link
Member Author

@joshhunt Go for it. The branch is up to date so it's yours to build upon.

@SunburnedGoose
Copy link
Member Author

SunburnedGoose commented Dec 30, 2016

FYI, the zip.js module has js files that are loaded by the zip.js file when the code needs the feature.. These can't be front-loaded in the bundle. I was going to try to copy the files during a build step to the vendors folder as we do now, but without the use of bower.

@bhollis
Copy link
Contributor

bhollis commented Dec 30, 2016 via email

@bhollis
Copy link
Contributor

bhollis commented Dec 30, 2016 via email

@delphiactual
Copy link
Contributor

delphiactual commented Dec 31, 2016

Couple of issues that remain on the webpack branch.

When running LoadoutBuilder the following error occurs:
Fixed this error by changing to tierString.toString().split and no it finishes loading but the tier drop down is broken...

angular.js:14328 TypeError: tierString.split is not a function
    at dimMinMax.controller.js:569
    at underscore.js:399
    at Function._.each._.forEach (underscore.js:153)
    at Function.groupBy (underscore.js:398)
    at step (dimMinMax.controller.js:568)
    at angular.js:19916
    at completeOutstandingRequest (angular.js:6111)
    at angular.js:6390

The following html files do not load with this error Failed to load resource: net::ERR_FILE_NOT_FOUND
[x] About
[x] Support
[x] Settings
[x] Filter
[x] Infuse
[x] Xur
[x] best-help

@delphiactual
Copy link
Contributor

@joshhunt I tried to get this working but something about context...

https://github.com/DestinyItemManager/DIM/blob/dev/app/scripts/shell/dimAppCtrl.controller.js#L141

@joshhunt
Copy link
Contributor

joshhunt commented Dec 31, 2016 via email

@delphiactual
Copy link
Contributor

I figured it out, I was missing the template part of the file and that did the trick #1308

@bhollis
Copy link
Contributor

bhollis commented Jan 9, 2017

Closing this because we're well on our way!

@bhollis bhollis closed this as completed Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants