When using the @graphql-codegen/client-preset
on large scale projects might want to enable code splitting or tree shaking on the client-preset
generated files. This is because instead of using the map which contains all GraphQL operations in the project, we can use the specific generated document types.
This plugin works for SWC only.
yarn add -D @graphql-codegen/client-preset-swc-plugin
You will need to provide the artifactDirectory
path that should be the same as the one configured in your codegen.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react({
plugins: [
['@graphql-codegen/client-preset-swc-plugin', { artifactDirectory: './src/gql', gqlTagName: 'graphql' }]
]
})
]
})
const nextConfig = {
// ...
experimental: {
swcPlugins: [
['@graphql-codegen/client-preset-swc-plugin', { artifactDirectory: './src/gql', gqlTagName: 'graphql' }]
]
}
}
{
// ...
jsc: {
// ...
experimental: {
plugins: [
['@graphql-codegen/client-preset-swc-plugin', { artifactDirectory: './src/gql', gqlTagName: 'graphql' }]
]
}
}
}
To publish a new version ensure you have done the following:
- Update the version in
package.json
- Update the
CHANGELOG.md
with the new version and changes - Commit the changes
- From GitHub Actions, run the
Rust plugin
workflow