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

WIP: Initial Webpack work #1306

Merged
merged 31 commits into from
Dec 31, 2016
Merged

Conversation

joshhunt
Copy link
Contributor

@joshhunt joshhunt commented Dec 30, 2016

As has been discussed over in #869, this represents the bulk of the initial work in getting Webpack up and running for bundling all of DIM.

Run it (at the moment) with npm start -s -- --watch. Everything should be mostly working (at least, everything looks alright. I can't transfer items atm due to a OriginHeaderDoesNotMatchKey error, I'm not sure if that's just Bungie updating slowly or an error I've introduced).

Note that I've updated the chrome manifest.json to point to the new generated/index.html, so you'll need to reload the extension.

We have all of the dependencies and application scripts bundle up into one JS file, as well as getting Webpack to manage styles and some static assets.

TODO:

  • Import external CSS (Hotkeys and Font Awesome). I guess we can either use CSS Loader + ExtractTextPlugin (so similar to how the Sass is built), or @import them in the main.scss file.
  • Sort out the random images that arent referenced correctly. Just using file-loader + const spartanUrl = require('./images/spartan.png') might be appropriate.
  • Create a proper 'watch' mode for development
  • Clean out the generated build so it doesnt keep accumulating with hashed files
  • Ensure 'production' build (minification) is working
    • Create new package.json script commands to make this easy to run
  • Understand the Chrome Extension deployment process and make sure that's all working properly.
  • Document new build and commands to run during development and production.

@@ -197,7 +200,7 @@
function unzipManifest(blob) {
return $q(function(resolve, reject) {
zip.useWebWorkers = true;
zip.workerScriptsPath = "vendor/zip.js/WebContent/";
zip.workerScriptsPath = 'zipjs/';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'zip' is not defined no-undef

@@ -197,7 +200,7 @@
function unzipManifest(blob) {
return $q(function(resolve, reject) {
zip.useWebWorkers = true;
zip.workerScriptsPath = "vendor/zip.js/WebContent/";
zip.workerScriptsPath = 'zipjs/';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'zip' is not defined no-undef

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sssh!

@joshhunt
Copy link
Contributor Author

joshhunt commented Dec 30, 2016

'Longer term' (as in it's probably not needed to merge this into master) we would want to understand how and where all the external dependencies are used and remove that ugly block of window._ = require('underscore').. at the top of app/index.js.

Also now that everything is seperate modules, we can remove the IIFE and "use strict" around all the files.

@bhollis
Copy link
Contributor

bhollis commented Dec 30, 2016

Wonderful!

What would it take to plug babel into the process so we can use babili and ng-annotate?

@joshhunt
Copy link
Contributor Author

Babel is already operating over all the javascripts, so any additional plugins should be fairly easy.

I'm not sure how Babili would go though. Last time I used it (a while ago) I had much difficulty getting it to do anything, so we can see how that goes I guess 😄

@SunburnedGoose
Copy link
Member

image

@delphiactual
Copy link
Contributor

npm start -s -- --watch

@joshhunt
Copy link
Contributor Author

🤔 just plain npm start should work - it does for me. I'm wondering if it's just a Windows issue... I might give it a spin in a Windows VM and see how it goes.

@delphiactual
Copy link
Contributor

delphiactual commented Dec 30, 2016

npm install generates the following errors on Windows

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN [email protected] requires a peer of webpack@^2.1.0-beta.19 but none was installed.
npm WARN [email protected] requires a peer of webpack@1 || ^2.1.0-beta but none was installed.

@delphiactual
Copy link
Contributor

delphiactual commented Dec 30, 2016

@joshhunt This is what I had to do to get it to work in Windows...

delphiactual@333d21d

EDIT: styles are not working but npm start completed

@joshhunt
Copy link
Contributor Author

The webpack.js change I guess would be due to different versions of node that were running locally.

Dropping down to a prev webpack version though is quite interesting though. I'll take at a look at them all and see what we can do.

@delphiactual
Copy link
Contributor

Yep, I was running an older version of node... 4.4.4 upgraded and reverted the changes to webpack.js and all is well there...

@delphiactual
Copy link
Contributor

@SunburnedGoose you forgot to npm install

@delphiactual
Copy link
Contributor

@joshhunt delphiactual@d73a87a fixed it for me they have not pushed new builds out yet that have the rc support but they are in their master branches

@SunburnedGoose
Copy link
Member

I ran install. I'll delete the folder.

2016-12-30_124748

@delphiactual
Copy link
Contributor

@joshhunt sent you a PR that loads font-awesome and gets webpack to work on windows.

@joshhunt
Copy link
Contributor Author

joshhunt commented Dec 30, 2016

@delphiactual 💃 great stuff!

@SunburnedGoose that exit status code is a bit funky. Looks like it might be related to sass/node-sass#1283 or npm/npm#11024. does npm remove node-sass; npm install node-sass work file for you?

@joshhunt
Copy link
Contributor Author

What is people's thoughts on the best way for generating the complete build, in regards to loading it up for the Chrome Extension? You'll note at the moment that the options url (and the url for DIM I guess) is now chrome-extension:/.../generated/index.html - Ideally this URL should be the same as before.

I'm thinking to utilise CopyWebpackPlugin and copy the manifest (and other supporting files, like icons and whatnot) into the app/generated folder and instructing developers to point the unpack Chrome extension to there. Personally, I think it would be somewhat nicer and cleaner to utilise that dist/chrome folder for this (and remove it from git with .gitignore).

I'm not 100% across how all this Chrome stuff works, so I'll have to defer to the expertise of others here.

}
},
setHash: 0
};
console.log({set});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space is required after '{' object-curly-spacing
A space is required before '}' object-curly-spacing

}
},
setHash: 0
};
console.log({set});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space is required after '{' object-curly-spacing
A space is required before '}' object-curly-spacing

@delphiactual
Copy link
Contributor

I did have to run npm rebuild node-sass after upgrading node

},
STAT_STRENGTH: {
value: 0,
tier: 0,
name: 'Strength',
icon: 'images/Strength.png'
icon: require('app/images/Strength.png'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to get these images working

screen shot 2016-12-31 at 11 08 33 am

But I don't really know where they're defined... This was my first guess, but this code doesn't appear to be executed when rendering the inventory page. console.log and breakpoints arent hit. Any idea where/how those images are being referenced?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code you changed is just for in LoadoutBuilder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh - that's why find wasnt working ;)

@joshhunt
Copy link
Contributor Author

What is people's thoughts on the best way for generating the complete build, in regards to loading it up for the Chrome Extension?...

Hmm... In thinking about this more, perhaps requiring developers to re-add the chrome extension isnt the best approach here (its a bit annoying, and would require updating the Bungie API origin header). Ideally, I would prefer to build into dist/

What if we instead rename app/ to src/ and build into app (and ensure that isnt comitted into git)? The naming would be a bit unconventional but it would ease the migration for existing developers.

Or are we okay with the one-time only pain of having to readd the extension and updating API settings?

@SunburnedGoose
Copy link
Member

Origin header takes a wildcard * btw.

@SunburnedGoose
Copy link
Member

@joshhunt After some googling, it seems that error was a regression in node v7.1 which is what I had :/

Updated to v7.3 and it works.

@joshhunt
Copy link
Contributor Author

joshhunt commented Dec 31, 2016

Ahh neat - I'm glad to hear that.

I'm pretty happy with the work that's here - I think this is at least at a state where it can go into DIM/webpack, if not dev.

The only thing left I think is to make sure that the packaging for Chrome Webstore is all good. Don't really know much about that one...

There's more that can be done, but I think this represents a pretty good 'MVP'

Copy link
Member

@SunburnedGoose SunburnedGoose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this differentiate between iOS Safari and Desktop Safari when supporting the last two versions? Just curious about the addition and removal of the Safari filter.

@joshhunt
Copy link
Contributor Author

Honestly, it was only there because I copied the config from the babel-present-env readme, and then I just removed it because I thought prev 2 versions is good enough. I'm indifferent as to what's actually used.

'Safari' is just for desktop. iOS is for iOS. See browserlist.

@SunburnedGoose SunburnedGoose merged commit 65f31a1 into DestinyItemManager:webpack Dec 31, 2016
@SunburnedGoose
Copy link
Member

Looks great and works fine on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants