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

Enable Webpack tree shaking #352

Merged
merged 8 commits into from
Oct 2, 2018
Merged

Conversation

willopez
Copy link
Member

@willopez willopez commented Oct 1, 2018

Resolves #351
Impact: minor
Type: feature

Issue

Wepack tree shacking was not enabled due to the following setting being in our .babelrc,
modules: commonjs

This PR removes that setting to effectively enable tree shaking(dead code elimination)

Solution

Follow NextJS' example when using a custom web server: https://github.com/zeit/next.js/blob/canary/examples/custom-server-express/server.js

Testing

  1. Rebuild app
  2. Complete the checkout flow, both login and as an anonymous user.
  3. Verify there are no errors

@willopez willopez changed the title Fix enable Webpack tree shaking Enable Webpack tree shaking Oct 1, 2018
@rosshadden
Copy link
Contributor

Okay this makes sense. So there are essentially two runtime contexts. One is the startup code (the server) and the other is the Next.js routes and associated code. You had to change everything in the server context, everything they import, and everything they export to use commonjs imports and exports, and then the Next.js context can be ES modules because Next imports them itself through webpack.

Nice work.

Copy link
Contributor

@rosshadden rosshadden left a comment

Choose a reason for hiding this comment

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

Looks good to me. I tested it as well, and had no issues. Also fixed merge conflicts that just appeared a few minutes ago.

@spencern
Copy link
Contributor

spencern commented Oct 2, 2018

@willopez @rosshadden it looks like there are two lint errors that are being flagged in CI.

@rosshadden
Copy link
Contributor

rosshadden commented Oct 2, 2018

They might have arisen from the merge conflicts. I'll take a look.

@rosshadden
Copy link
Contributor

rosshadden commented Oct 2, 2018

Yeah my fault. I saw session in both sides of the diff and didn't notice express changed to cookie upstream. Fixed.

…commerce/reaction-next-starterkit into fix-enable-webpack-tree-shaking
@willopez willopez merged commit 42e8b97 into develop Oct 2, 2018
@willopez willopez deleted the fix-enable-webpack-tree-shaking branch October 2, 2018 18:59
This was referenced Jan 15, 2019
@spencern spencern mentioned this pull request Jan 25, 2019
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.

3 participants