-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: remove globalThis
check and align with what bundlers can accept
#4022
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
546c13f
remove globalThis process env check
JoviDeCroock b0ca7e0
add eslint ignore as there was before
JoviDeCroock cbb05cf
Update src/jsutils/instanceOf.ts
JoviDeCroock 0b8e107
remove unused directive
JoviDeCroock 157490b
update check to use globalThis.process
JoviDeCroock 5b3f00e
add docs
JoviDeCroock 6b6d7d3
run prettier
JoviDeCroock f57c710
add spelling checks
JoviDeCroock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ overrides: | |
- clsx | ||
- infima | ||
- noopener | ||
- Vite | ||
- craco | ||
- esbuild | ||
- swcrc | ||
- noreferrer | ||
- xlink | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
title: Going to production | ||
category: FAQ | ||
--- | ||
|
||
GraphQL.JS contains a few development checks which in production will cause slower performance and | ||
an increase in bundle-size. Every bundler goes about these changes different, in here we'll list | ||
out the most popular ones. | ||
|
||
## Bundler-specific configuration | ||
|
||
Here are some bundler-specific suggestions for configuring your bundler to remove `globalThis.process` and `process.env.NODE_ENV` on build time. | ||
|
||
### Vite | ||
|
||
```js | ||
export default defineConfig({ | ||
// ... | ||
define: { | ||
'globalThis.process': JSON.stringify(true), | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}, | ||
}); | ||
``` | ||
|
||
### Next.js | ||
|
||
```js | ||
// ... | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
webpack(config, { webpack }) { | ||
config.plugins.push( | ||
new webpack.DefinePlugin({ | ||
'globalThis.process': JSON.stringify(true), | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
); | ||
return config; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; | ||
``` | ||
|
||
### create-react-app | ||
|
||
With `create-react-app`, you need to use a third-party package like [`craco`](https://craco.js.org/) to modify the bundler configuration. | ||
|
||
```js | ||
const webpack = require('webpack'); | ||
module.exports = { | ||
webpack: { | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'globalThis.process': JSON.stringify(true), | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
], | ||
}, | ||
}; | ||
``` | ||
|
||
### esbuild | ||
|
||
```json | ||
{ | ||
"define": { | ||
"globalThis.process": true, | ||
"process.env.NODE_ENV": "production" | ||
} | ||
} | ||
``` | ||
|
||
### Webpack | ||
|
||
```js | ||
config.plugins.push( | ||
new webpack.DefinePlugin({ | ||
'globalThis.process': JSON.stringify(true), | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
); | ||
``` | ||
|
||
### Rollup | ||
|
||
```js | ||
export default [ | ||
{ | ||
// ... input, output, etc. | ||
plugins: [ | ||
minify({ | ||
mangle: { | ||
toplevel: true, | ||
}, | ||
compress: { | ||
toplevel: true, | ||
global_defs: { | ||
'@globalThis.process': JSON.stringify(true), | ||
'@process.env.NODE_ENV': JSON.stringify('production'), | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
]; | ||
``` | ||
|
||
### SWC | ||
|
||
```json title=".swcrc" | ||
{ | ||
"jsc": { | ||
"transform": { | ||
"optimizer": { | ||
"globals": { | ||
"vars": { | ||
"globalThis.process": true, | ||
"process.env.NODE_ENV": "production" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.