[WIP] Introduce build step to reduce CLI size #217
Conversation
|
@cspotcode I currently get the following error when trying to run
Any ideas on how this might be solved? |
|
@crutchcorn not sure since I don't know any of the context for that error. If you run webpack with minification turned off, then the emitted file should be readable, and you can figure out the context. |
|
Hmm. Good call. The error was created with:
Without minification, the error is as such:
|
|
This seems like it was worked around by @cspotcode by hotpatching https://github.com/cspotcode/plop/blob/de9f08b37c15d001e2414fe765740aa955db895b/patches/rechoir Maybe you can provide some insight to what this is and how we might be able to unblock ourselves without hotpatching? Is this a bug upstream? EDIT: This isn't a bug upstream. This is simply a hotpatch to get |
|
Oh yeah, I remember that. Rechoir needs to do certain Webpack has a mechanism called The tricky part is that most require calls in that file should be analyzed and bundled. So you can't completely exclude the file from parsing via
You could also send a PR to rechoir, but I'm not 100% sure what that PR should look like. |
|
I tried leaving in new webpack.IgnorePlugin({
resourceRegExp: /\./,
contextRegExp: /rechoir/
}),Simply generates: if (Object.keys(!(function webpackMissingModule() { var e = new Error("Cannot find module 'undefined'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).extensions).indexOf(ext) !== -1) {
return true;
}By design: webpack/webpack#2858 I think https://webpack.js.org/configuration/resolve/ I'll take another stab at hotpatching this tomorrow |
…or extensions, clean up webpack config
chore: add require fallback to webpack require, use default require for extensions, clean up webpack config
|
I may have initially opened this PR but all of the heavy lifting of getting this finally working goes to @evelynhathaway. She's the one that got this working finally in a place where I feel comfortable with the pros and cons Here's where we're at: Plop, after this PR, will be 1.2MB distributed. From 48MB, that's a shrinkage of 40x. This PR does not require Instead, this new method relies on exposed Webpack hooks that allow us to modify the behavior of Webpack's There are some minor downsides, however:
That said, let's look at what we're planning for next steps. Next StepsThis PR will be a "breaking change". Nothing in the API should change, but we previously weren't documenting how to handle deps such as We're also acutely aware of how drastic of a change this is and how subtly things could (theoretically) break without being immediately noticed. As such, while this PR is fully functional as far as my testing has shown, we will not be merging this in immediately. Instead, @evelynhathaway has mentioned that she'd be willing to help us get e2e testing in our CLI repo. We plan to complete that work and merge that before merging this PR. This should allow us to be more confident in bigger changes moving forward. Webpack PluginAfter thinking through this a bit further (both on my own and in discussions with @evelynhathaway ), I think we should make this Webpack plugin available as a separate NPM package. The plugin allows Webpack to bundle static assets, but still allow dynamic resolution of However, because of it's tight coupling to Plop, we'd like to keep this plugin in the Making this plugin a dedicated package would allow us to:
We're thinking that the dedicated plugin package should be done after merging this PR in (which is after e2e tests). @amwmedia, do you have any thoughts on this? Any opposition on potentially adding @evelynhathaway to the PlopJS org in the future to allow this? |
The idea behind this PR came from #206. This PR is a WIP migration of that same idea without yarn or hotpatches
EDIT: See comment #217 (comment)