-
Notifications
You must be signed in to change notification settings - Fork 704
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
Webpack all the things #640
Conversation
5efab30
to
a7718fa
Compare
So, a word of caution: I believe some of the libs in |
@astorije the removed libs were not modified by us |
^- only contains large deltas, which suggests that those libraries were only ever added or updated. |
a7718fa
to
2c4a924
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor changes and some naive and stupid questions as I have never used webpack, but good stuff overall!
module.exports = { | ||
entry: "./client/js/lounge.js", | ||
resolve: { | ||
extensions: ["", ".js"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question than #640 for the record: why do we need ""
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it allows importing without the ".js"
extension in import
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah, makes sense! Do we want to allow both with and without the extension? Or force one or the other format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per our discussion on IRC, could you remove that section altogether and rely on the defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks like that works fine!
@@ -7,6 +7,5 @@ coverage/ | |||
# See https://docs.npmjs.com/misc/scripts | |||
client/fonts/ | |||
client/js/bundle.js | |||
client/js/libs.min.js.map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No .map
anymore? Is that on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This webpack config doesn't produce source maps, but no reason it couldn't--I'll update it to produce inline source maps (so no need for an extra file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not inline the source map. Thats a lot of useless data to be included.
import "./roundBadgeNumber"; | ||
import "./tojson"; | ||
import "./tz"; | ||
import "./users"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sure wish there was a way to do import "./*";
but apparently there is no such thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, quite intentionally :) (That would cause an import cycle, for one thing!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you could locate the loading file outside of the directory (Ruby-style). But yeah, whatever :-)
import "jquery-ui/ui/widgets/sortable"; | ||
import Mousetrap from "mousetrap"; | ||
import Handlebars from "handlebars/runtime"; | ||
import "notification-polyfill"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that polyfill still necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://caniuse.com/#feat=notifications hm, not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok maybe let's keep it for now then. Sigh...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like IE still doesn't have notification support, so yeah.
|
||
import "./libs/jquery/inputhistory"; | ||
import "./libs/jquery/tabcomplete"; | ||
import "./libs/jquery/stickyscroll"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe all these libs by @erming are on npm, but also that we have monkey-patched these over time. A great contribution would be diff-ing ours with the upstream ones (because, yeah, they have evolved on the upstream project too...), open PRs on @erming's repos, and as they are being merged, move these to use the npm versions :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to ultimately remove all of these libs as dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@astorije These "libraries" were so heavily modified that I would consider them part of Lounge's code and not vendor.
"mocha": "3.0.2", | ||
"mousetrap": "1.6.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment, version in repo is 1.4.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
"npm-run-all": "3.1.0", | ||
"stylelint": "7.3.1", | ||
"uglify-js": "2.7.3", | ||
"urijs": "1.18.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version in repo is 1.14.1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPM only has back to 1.16.1 of this lib, so I've rolled back to that.
@@ -1,5 +1,5 @@ | |||
var _ = require("lodash"); | |||
var package = require("../package.json"); | |||
var packageJson = require("../package.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#399 did something similar with server code, but went with pkg
. I have no preference over which one, but it would be nice to use the same one :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@@ -64,11 +63,16 @@ | |||
"eslint": "3.6.0", | |||
"font-awesome": "4.6.3", | |||
"handlebars": "4.0.5", | |||
"imports-loader": "0.6.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'm getting this, why do we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make $
appear in libs without calling require
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, didn't think of that. Clever way to do so too, cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should explicitly require the needed stuff without automagic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is even possible or reasonable. Unless I am mistaken, I believe @nornagon is talking about real libs (like jquery-ui) and not our "libs" in client/js/libs
.
Or maybe there is a different/better way to do so, I don't know. I think this is good enough for a first shot at it and we can improve later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nornagon I see you added imports for $ and others, is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports-loader
is still being used to provide the jQuery
global variable to the jquery libs, which I haven't changed in this diff.
@@ -1,5 +1,17 @@ | |||
const webpack = require("webpack"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, why do you need to require webpack in your second commit? It seems like it was not needed for the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this one uses webpack
in its body, to refer to webpack.optimize.CommonsChunkPlugin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh yeah, I missed that (aka reviewing PRs at 1AM 😅).
Too bad we can't use import
here though, the irony :-)
Let me know when you're done updating this :-) |
2c4a924
to
e67e0e3
Compare
Ready for another look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 minor comment and 1 very small change and then we should be ok :) (I'll test after that before approving this though).
"istanbul": "0.4.5", | ||
"jquery": "2.1.1", | ||
"jquery-ui": "1.12.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did 1.12.1 work as expected? Did the version bump turn out to fix #494 by any miracle?
module.exports = { | ||
entry: "./client/js/lounge.js", | ||
resolve: { | ||
extensions: ["", ".js"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per our discussion on IRC, could you remove that section altogether and rely on the defaults?
"build:handlebars": "handlebars client/views/ -e tpl -f client/js/lounge.templates.js", | ||
"build:webpack": "webpack", | ||
"watch": "webpack -w", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also get a script to automatically start the server and webpack's watch within a single command for development purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
@@ -1,5 +1,5 @@ | |||
var _ = require("lodash"); | |||
var package = require("../package.json"); | |||
var pkg = require("../package.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You touched client.js
for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't for no reason. package
is a reserved word in ES6, and webpack was refusing to compile this file without this rename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you add "use strict";
at the top (and feel free to do so on files you changed as it's a really good thing to have), implements
, interface
, let
, package
, private
, protected
, public
, static
, and yield
become reserved keywords.
const webpack = require("webpack"); | ||
|
||
module.exports = { | ||
entry: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for future proofing, will it be easy to add our postcss
stuff into this config, or it will have to be rewritten for an additional export or whatever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, should be easy to add. See https://github.com/postcss/postcss-loader.
e67e0e3
to
f06476c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job, @nornagon! Alright people, let's ! And improve along the way when necessary.
@@ -14,16 +14,16 @@ | |||
"scripts": { | |||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -r test/fixtures/env.js test/**/*.js", | |||
"start": "node index", | |||
"start-dev": "npm run watch & npm run start", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only runs the webpack watch and blocks, and then never runs the lounge itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how &
works (perhaps you're thinking of &&
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a couple of things that need to be addressed:
babel-core
has to be added to package.json
:
ERROR in Cannot find module 'babel-core'
npm WARN [email protected] requires a peer of babel-core@^6.0.0 but none was installed.
Vendor file contains inline source maps,and the file is absolutely huge (554kb!!), generate an external .map
.
Source map not being generated for bundle.js
(make it external too)
inputhistory
requires jQuery, but the dependancy is not resolved: Uncaught ReferenceError: jQuery is not defined
start-dev
only runs webpack and doesn't start the server.
I think uglifyjs should be kept to generate a lot smaller files (especially vendor). bundle.js
drops at least half in size with uglify plugin.
Also, this needs to be rebased on master due to merge of slideout menu (new libs/slideout.js file) |
f06476c
to
51f9cdd
Compare
Added babel-core. Whoops. Source maps inlined in vendor.bundle.js are there in the upstream code, it's not webpack that's adding them. The config in this diff wasn't generating source maps at all for our own code; I've tweaked it to generate them and put them in separate files. With this change:
I experimented with uglify and it did significantly drop the file sizes:
but at the cost of 2x build time:
so I don't think it makes sense to uglify during dev. Many projects using webpack have a separate config for prod vs. dev, and I'd be happy to work on that, but perhaps it could be in a followup PR? I can't reproduce your issue with inputhistory. I tried building from a clean repo and I don't see any error. This is the code webpack is generating: /*** IMPORTS FROM imports-loader ***/
var jQuery = __webpack_require__(1);
/*!
* inputhistory
* https://github.com/erming/inputhistory
* v0.3.1
*/
(function ($) {
$.inputhistory = {};
/* ... */
})(jQuery); which seems fine to me. In addition, the functionality (pressing up to get to old messages) works just fine. I also can't reproduce your issue with
|
51f9cdd
to
352a1b9
Compare
Also rebased, and used |
Just realised the start-dev issue might be a windows thing, are you testing on windows @xPaw ? |
var keys = { | ||
backspace: 8, | ||
tab: 9, | ||
up: 38, | ||
down: 40 | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not lint these, I still want them to come from upstream project (so, npm) after backporting our changes. I started on one, need to continue.
f31a45b
to
3b0d324
Compare
); | ||
module.exports = function(context) { | ||
return window.JSON.stringify(context); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to be renamed to toJSON.js
, otherwise the handlebars loader will be unable to resolve it on case-sensitive file systems.
291aa97
to
37c29f3
Compare
@astorije I've reverted changes to erming's libs so they are untouched by this PR. Also squashed it. |
37c29f3
to
4198207
Compare
Nooooo, I was still trying to test some things, which are now gone as you've reverted them as part of one of the commits. Can you revert this, please? ( |
This will need rebased again. What's the plan with this, it would be great to have this, then we can start splitting up our monolithic codebase. |
@YaManicKill astorije wanted something in this PR before merge. |
@xPaw, reminder to un-squash this for now please? :) |
@astorije sorry I am not able to un-squash this. |
One of you should have it on your reflog, and if not, the server should hav eit on the reflog, no? |
Uuuuh so you mean what I spent 1-2 days working on is lost? Please no! |
@astorije fortunately not lost! This should be it: https://github.com/nornagon/lounge/commits/291aa975c5a9847404b7fa928b3959773f2a5a7a For reference: https://8thlight.com/blog/sandro-padin/2015/06/08/help-i-just-force-pushed-to-master.html |
@astorije Are the things you were testing related to this PR, or are we happy to go with this now? Would be good to get this merged asap, so that other people building PRs can build off this rather than the old code. |
@nornagon You've still got some lint errors. Could you fix these and rebase? Would be great to get this into a release soon. |
I've pushed a fixed branch under our repo: https://github.com/thelounge/lounge/tree/pr/640 It's a lot easier to deal with the branch within the repo rather than dealing with the fork. |
Closed in favour of fixed #817. |
Builds on top of #609. Drops uglify in favor of webpack. Uses code splitting and imports-loader to get everything to play nicely together.