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

Use HtmlWebpackPlugin to import all assets (importing chunks in order) #1775

Merged

Conversation

thomasbertet
Copy link
Contributor

@thomasbertet thomasbertet commented Aug 31, 2017

Issue: #1411

What I did

  • Removing manuel insertion of assets inside a index/iframe.html template.
  • Use HtmlWebpackPlugin to import in correct order all chunks.

How to test

  • Have a build with multiple split points, everything should be loaded in order.

Is this testable with jest or storyshots?
Not sure how yet.. will do.

Does this need a new example in the kitchen sink apps?
No.

Does this need an update to the documentation?
No.

If your answer is yes to any of these, please make sure to include it in your PR.

@codecov
Copy link

codecov bot commented Aug 31, 2017

Codecov Report

Merging #1775 into release/3.3 will decrease coverage by 0.08%.
The diff coverage is 20%.

Impacted file tree graph

@@               Coverage Diff               @@
##           release/3.3    #1775      +/-   ##
===============================================
- Coverage        23.14%   23.05%   -0.09%     
===============================================
  Files              253      248       -5     
  Lines             5756     5703      -53     
  Branches           691      684       -7     
===============================================
- Hits              1332     1315      -17     
+ Misses            3924     3889      -35     
+ Partials           500      499       -1
Impacted Files Coverage Δ
app/react/src/server/config/webpack.config.prod.js 0% <ø> (ø) ⬆️
app/react/src/server/config/webpack.config.js 0% <ø> (ø) ⬆️
app/vue/src/server/config/webpack.config.js 0% <ø> (ø) ⬆️
app/vue/src/server/config/webpack.config.prod.js 0% <ø> (ø) ⬆️
lib/ui/src/modules/ui/components/layout/index.js 76.27% <ø> (ø) ⬆️
...i/src/modules/ui/components/stories_panel/index.js 100% <ø> (ø) ⬆️
app/react/src/server/middleware.js 0% <0%> (ø) ⬆️
app/vue/src/server/middleware.js 0% <0%> (ø) ⬆️
app/react/src/server/build.js 0% <0%> (ø) ⬆️
...ct-native/src/server/config/webpack.config.prod.js 0% <0%> (ø) ⬆️
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db01fac...99e9ab3. Read the comment docs.

Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

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

Code looks good to me,

Should we add this behavior to the cra-kitchen-sink to make sure it actually works?

The unit tests for this tests only a really small part of the puzzle. A huge portion is inside webpack, and we'd like to verify it works, not just know the order is correct.

cc @tmeasday @Hypnosphi @shilman

@Hypnosphi
Copy link
Member

I agree.
@thomasbertet please add a custom webpack config for examples/cra-kitchen-sinks which will, for example, create a separate vendor chunk

@thomasbertet
Copy link
Contributor Author

Fine by me, will add =) I'll let you know.

@thomasbertet
Copy link
Contributor Author

thomasbertet commented Aug 31, 2017

@Hypnosphi after some digging around CRA, we cannot split bundles yet facebook/create-react-app#2206 (at least, not using the webpack config). Meaning, splitting vendors & app cannot be done easily using the CommonChunksPlugin. Correct me if I'm wrong!

I may need then to set some split points inside the code of cra-kitchen-sinks, WDYT ? This way I will be able to give it a name (using the magic comment of webpack import syntax) and test some cases.

@Hypnosphi
Copy link
Member

Hypnosphi commented Aug 31, 2017

I mean a custom webpack config for storybook, not for app itself

@thomasbertet
Copy link
Contributor Author

Ok then, here is my findings:

  • When you have split points in your app, you need to load them after preview.bundle.js (preview contains webpack's bootstrapping)
  • When you use CommonsChunkPlugin in .storybook/webpack.config.js to extract, say, a "vendor" bundle, then you will want to load it before preview.bundle.js. (vendor contains webpack's bootstrapping)

These two use cases could not be solved using the quick fix in this PR in its current state.
We might want to add extra sorting to assets so that they are inserted in the correct order depending on the dependency graph.

When using the statsJson, the https://webpack.js.org/api/stats/#chunk-objects has a parent prop we can use to reorder correctly the chunks.

Maybe we should consider adding a similar logic as HtmlWebpackPlugin there: https://github.com/jantimon/html-webpack-plugin/blob/master/lib/chunksorter.js ?

Please correct me if I'm misunderstanding something, any help appreciated 👍

Also, maybe @SpaceK33z you might want to give us a thought as its webpack's related :)

Thanks!

@SpaceK33z
Copy link
Member

SpaceK33z commented Sep 1, 2017

Hi, this part of webpack is not my area of expertise, but what I can say is that in webpack 4 the order should not matter anymore (source, ctrl+f on 'pure jsonp'). But I realize this will take some time so for now this info is useless 😆.

@Hypnosphi
Copy link
Member

Maybe we should consider adding a similar logic as HtmlWebpackPlugin

Maybe we should consider just using the plugin =)

@thomasbertet
Copy link
Contributor Author

thomasbertet commented Sep 1, 2017

@Hypnosphi I implemented a solution to this with HtmlWebpackPlugin.

I tried my best with the little knowledge I have from the codebase to not break anything.

Could you find the time to try it, and guide me through where I can create test cases to improve this PR ?

Thanks in advance !

ps: A a side note, I had issues with addons channels, couldn't really fix it, so I commented out everything addon related to test, with hope this is a development related issue. Please let me know if some is not working :)

@thomasbertet thomasbertet changed the title Load chunks after the preview bundle Use HtmlWebpackPlugin to import all assets (importing chunks in order) Sep 1, 2017
@ndelangen
Copy link
Member

I like where this is going! Great work @thomasbertet

@Hypnosphi Hypnosphi self-requested a review September 1, 2017 23:50
@Hypnosphi
Copy link
Member

Works great! Please make the same chages to app/vue (yeah, the duplication isn't cool, but it's kinda by design as far as I know)

@thomasbertet
Copy link
Contributor Author

Thanks @ndelangen ! Really appreciate this :-)
It feels good to finally help improve storybook.

Will definately do the same for vue. Thanks @Hypnosphi !

@thomasbertet
Copy link
Contributor Author

@Hypnosphi I added it for vue as well.

Ready to take it to the next level, please let me know if I need to do something else.

@ndelangen
Copy link
Member

I will test this now.

Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

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

Tested the regular and static build for cra and vue, works great!

I added a custom webpack config with a vendor chunk for vue too.

@Hypnosphi
Copy link
Member

@ndelangen should we probably merge it into release/3.3 not master?

Copy link
Member

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

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

LGTM

@shilman
Copy link
Member

shilman commented Sep 5, 2017

I noticed changes for react/vue but not for RN, which also has a very similar webpack/preview setup (in addition to the device side of things). Do we need to change RN as well?

@Hypnosphi
Copy link
Member

Hypnosphi commented Sep 5, 2017

@shilman As far as I understand, RN app doesn't have a preview entry in webpack config:
https://github.com/storybooks/storybook/blob/master/app/react-native/src/server/config/webpack.config.js#L9

It probably could still benefit from HtmlWebpackPlugin, but #1411 looks irrelevant to it

@Hypnosphi Hypnosphi changed the base branch from master to release/3.3 September 5, 2017 00:22
@ndelangen
Copy link
Member

@thomasbertet I think we should try to keep the apps in sync as much as possible.

Do you want to bring these changes to the RN app as well? Or do you want me to do it?

@thomasbertet
Copy link
Contributor Author

thomasbertet commented Sep 5, 2017 via email

@ndelangen
Copy link
Member

After Angular app has been merged in, we will be refactoring out most of the duplication.

So no it's not our goal to keep it exactly like this; though it's also not a goal to abstract away all forms of duplication. Nothing hurts a codebase more than early abstraction.

@thomasbertet
Copy link
Contributor Author

@ndelangen this is it =) I added the same behavior for RN & the CRNA example.

@ndelangen
Copy link
Member

I will test it @thomasbertet, you're awesome! 💪

@ndelangen
Copy link
Member

Tested both the crna-example and the react-native-vanilla ✅

@ndelangen ndelangen requested review from tmeasday and removed request for tmeasday September 6, 2017 12:59
@ndelangen ndelangen merged commit 40c652d into storybookjs:release/3.3 Sep 6, 2017
@thomasbertet
Copy link
Contributor Author

Great ! Thanks @ndelangen 👍

@thomasbertet thomasbertet deleted the fix-ordering-chunk-load branch September 6, 2017 13:08
@ndelangen
Copy link
Member

Congrats @thomasbertet !

I hope more PRs like this will follow! 🙇

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

Successfully merging this pull request may close these issues.

None yet

5 participants