-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/16.x.x' into backport-16.x.x
- Loading branch information
Showing
11 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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