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

feat: optionally strip non-client or non-server code #6149

Merged
merged 10 commits into from Nov 24, 2019

Conversation

manniL
Copy link
Member

@manniL manniL commented Jul 28, 2019

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

We already have process.client and process.server that take care of separating "client" and "server" code (if needed). However, it can sometimes be hard to control that in 3rd party dependencies.

With this change, the webpack define plugin will set the typeof window check to object on client and undefined on server, so the code can (and will be) correctly removed by webpack.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@manniL manniL requested a review from clarkdo July 28, 2019 08:37
@clarkdo
Copy link
Member

clarkdo commented Jul 28, 2019

What will happen to jsdom case?

@codecov-io
Copy link

codecov-io commented Jul 28, 2019

Codecov Report

Merging #6149 into dev will decrease coverage by 0.1%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #6149      +/-   ##
==========================================
- Coverage   95.79%   95.69%   -0.11%     
==========================================
  Files          78       78              
  Lines        2714     2718       +4     
  Branches      702      706       +4     
==========================================
+ Hits         2600     2601       +1     
  Misses         99       99              
- Partials       15       18       +3
Flag Coverage Δ
#e2e 100% <ø> (ø) ⬆️
#fixtures 64.6% <57.14%> (-0.06%) ⬇️
#unit 92.2% <57.14%> (-0.1%) ⬇️
Impacted Files Coverage Δ
packages/config/src/config/build.js 100% <ø> (ø) ⬆️
packages/webpack/src/config/client.js 98.11% <100%> (ø) ⬆️
packages/webpack/src/config/server.js 100% <100%> (ø) ⬆️
packages/webpack/src/config/base.js 87.96% <40%> (-2.43%) ⬇️

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 e9945b0...0d9f76c. Read the comment docs.

@manniL
Copy link
Member Author

manniL commented Jul 28, 2019

Made it optional but couldn't find a better name for it 🙈

clarkdo
clarkdo previously approved these changes Jul 28, 2019
packages/webpack/src/config/client.js Outdated Show resolved Hide resolved
@@ -120,6 +120,12 @@ export default class WebpackBaseConfig {
'process.mode': JSON.stringify(this.mode),
'process.static': this.buildContext.isStatic
}
if (this.buildContext.buildOptions.aggressiveCodeRemoval) {
env['typeof process'] = JSON.stringify(this.isServer ? 'object' : 'undefined')
Copy link
Member

Choose a reason for hiding this comment

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

Values are the same. Can we refactor the right hand part to a const?

packages/config/src/config/build.js Show resolved Hide resolved
@manniL manniL changed the title feat: strip non-client or non-server code by default feat: optionally strip non-client or non-server code Aug 5, 2019
@manniL manniL marked this pull request as ready for review August 21, 2019 16:39
@pi0 pi0 added this to Ready to Review in Nuxt v2.10 Aug 21, 2019
@stale stale bot added the stale label Sep 24, 2019
@nuxt nuxt deleted a comment from stale bot Sep 26, 2019
@stale stale bot removed the stale label Sep 26, 2019
@stale stale bot added the stale label Oct 22, 2019
@pi0 pi0 removed the stale label Oct 23, 2019
@nuxt nuxt deleted a comment from stale bot Oct 23, 2019
@pi0 pi0 merged commit 75bb088 into dev Nov 24, 2019
@pi0 pi0 deleted the feat/strip-code-if-applicable branch November 24, 2019 15:39
@pi0 pi0 mentioned this pull request Nov 26, 2019
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Nuxt v2.10
  
Ready to Review
Development

Successfully merging this pull request may close these issues.

None yet

7 participants