-
Notifications
You must be signed in to change notification settings - Fork 91
Use webpack to (re)generate index HTML files #839
Conversation
Conflicts: lib/index-static.jsx lib/routes.jsx
@mmmavis do you want to take a look at this one? It's a bit of a doozy so no worries if not, but I think you could learn a lot from it. This stuff is also pretty new to me, so I could use a second opinion :) If you accept the mission, I recommend trying out the following to manually test things:
|
@@ -70,6 +70,32 @@ function handleError() { | |||
}); | |||
} | |||
|
|||
function createIndexFileStream() { | |||
var stream = new PassThrough({ objectMode: true }); |
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.
@toolness I'll get to this PR today - hopefully I won't take too long this time 😶 |
No worries! It's not a big rush either, so feel free to take your time and ask any questions that come up. |
Sorry for the delay - my other tickets took longer than I expected. Will work on this one today 😁 |
entry: entry, | ||
target: 'node', | ||
devtool: 'sourcemap', | ||
externals: function(context, request, callback) { |
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.
Hey @toolness could you help me understand what context
and request
are? I see they being mentioned on http://webpack.github.io/docs/configuration.html#externals but the doc doesn't go in detail.
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.
Ah yeah, this was annoying for me to figure out, because webpack's documentation is sparse in some places. :( I think I literally just console.log
'd the arguments to get an idea of what they actually were, lol. Not a very strong sign of forwards-compatibility, but the good news is that at least we'll know when it breaks, since that code is executed so often!
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.
heh, console.log
is always good! I think it'll help a lot for understanding webpack related stuff especially... 😶
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.
Yeah, webpack can be really confusing. :( Hopefully it will improve with age...
Hi @toolness
Working perfectly.
Yes, this works great as well. (files got regenerated themselves and with manual refresh on browser I was able to see the changes)
Question: by identical did you mean comparing the code in those files or? |
}, function(err, html) { | ||
if (err) { | ||
return this.emit('error', err); | ||
} |
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.
(commenting on this line instead since Github doesn't let me do it on line 19)
I'm just curious why we have to reverse the array. Does it matter which url gets popped first? Is it to preserve the ordering that the URLs get set in indexStatic.URLS
?
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.
Ah, yeah, it is to preserve the ordering. Instead of using .pop()
in the _read
method I should've just used .shift()
, but because I constantly get confused between shift and unshift and didn't want to look up the docs, at the time I just opted to reverse the array being popped-from instead! 😅
Yeah, um, I really should've done this myself before issuing this PR, but I think it'd be useful for both of us to do it, just to make sure. Basically I mean e.g. using the current develop branch without this PR and generating the files, then renaming the |
As per the discussion at: mozilla#839 (comment)
} | ||
}; | ||
|
||
self.build = function(cb) { |
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.
Hi @toolness , I just wanna check I'm getting this right.
So this part means
if index-static.bundle.js
has been generated, move on
if it's still being build, we make sure it doesn't get rebuilt within 100ms?
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.
Very close--basically we don't want multiple builds going on simultaneously, so we just block any additional requests after the first one to wait until the first one is finished. They "wait" by coming back every 100ms and checking to see if the first one is done yet.
It's kind of an overly-complicated way to do it honestly. Maybe I should use a singleton promise instead?
Hey @toolness could you rebase this PR with |
I rebased on my local branch but |
Ugh, yeah, actually don't worry about diffing the files--even doing this kind of diff on the exact same branch appears to fail, because the |
Alrighty! This PR totally make sense to me now! Thanks for walking me through @toolness 👯 👯 👯 👯 👯 |
Use webpack to (re)generate index HTML files
Wooot thanks mavis! |
While researching #585 I ran into jlongster's Backend Apps with Webpack series of posts and decided to familiarize myself with using webpack in node (as opposed to the browser) by using it to watch and rebuild our static index files during
gulp watch
.This has a number of benefits:
lib/travis.js
will trigger a full rebuild of the index HTML files, even though that file has nothing to do with rebuilding index HTML files.node-jsx
).We haven't completely decoupled ourselves from that toolchain yet, as everything outside ofgulp watch
still uses it, but the plan is to migrate away from it, so that our build toolchain is ultimately simplified.We're still usingThis should also make migrating to Use a lightweight server that dynamically renders HTML #585 (and quickly iterating on the server during development) easier.node-jsx
but only for running node-side tests.Limitations:
sitemap.xml
file ingulp watch
anymore. Hopefully not that big a deal.Until we've completely replaced our use ofnode-jsx
with webpack, we're moving away from dev/prod parity, which isn't awesome. So we should finish that migration ASAP.test/index-static.test.js
test is slower because it builds the webpack bundle now, but I'd rather it just run slower than assume the developer manually builds it before running the test, and then have devs get frustrated when they change the code but the tests still fail.We're building the index HTML generator bundle inThe index HTML generator bundle is in thedist/index-static
, which probably isn't awesome because it's really just an intermediate file that isn't intended for distribution. As such, we should probably put it in some sort of intermediate directory that's also in our.gitignore
.build
directory, intended for intermediate build files rather than files to be distributed.