Skip to content

Commit d991677

Browse files
authored
✨ feat: Use drupal vite plugin (#166)
1 parent 481de2e commit d991677

File tree

9 files changed

+1371
-1241
lines changed

9 files changed

+1371
-1241
lines changed

starters/react-router/app/integration/forms/ContactForm/function.server.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { graphql } from '~/graphql/gql.tada'
2-
import { getClient } from '~/utils/client.server'
2+
import { getDrupalClient } from 'drupal-vite/client'
33
import { ContactFormSchema } from './schema'
44
import { composable } from 'composable-functions'
55

@@ -17,14 +17,7 @@ const contactMutation = graphql(`
1717
async function submitContactForm(
1818
input: ContactFormSchema,
1919
) {
20-
const client = await getClient({
21-
url: process.env.DRUPAL_GRAPHQL_URI as string,
22-
auth: {
23-
uri: process.env.DRUPAL_AUTH_URI as string,
24-
clientId: process.env.DRUPAL_CLIENT_ID as string,
25-
clientSecret: process.env.DRUPAL_CLIENT_SECRET as string,
26-
},
27-
})
20+
const client = await getDrupalClient()
2821

2922
const inputArray = Object.entries(input).map(([key, value]) => ({
3023
key,

starters/react-router/app/routes/$.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import type { EntityFragmentType } from '~/graphql/types'
66
import NodeArticleComponent from '~/integration/node/NodeArticle'
77
import NodePageComponent from '~/integration/node/NodePage'
88
import TermTagsComponent from '~/integration/taxonomy/TermTags'
9-
import { getClient } from '~/utils/client.server'
109
import { calculatePath } from '~/utils/routes'
1110
import { calculateMetaTags } from '~/utils/metatags'
1211
import { Header, Footer } from '~/components/blocks'
1312
import { NodeArticleFragment, NodePageFragment } from '~/graphql/fragments/node'
1413
import { TermTagsFragment } from '~/graphql/fragments/terms'
1514
import { MenuFragment, MenuItemFragment } from '~/graphql/fragments/menu'
1615
import { redirect } from 'react-router'
16+
import { getDrupalClient } from 'drupal-vite/client'
1717

1818
export function meta({ data }: Route.MetaArgs) {
1919
if (!data) {
@@ -55,14 +55,7 @@ export function meta({ data }: Route.MetaArgs) {
5555
export async function loader({ params, request }: Route.LoaderArgs) {
5656
const path = calculatePath({ path: params['*'], url: request.url })
5757

58-
const client = await getClient({
59-
url: process.env.DRUPAL_GRAPHQL_URI as string,
60-
auth: {
61-
uri: process.env.DRUPAL_AUTH_URI as string,
62-
clientId: process.env.DRUPAL_CLIENT_ID as string,
63-
clientSecret: process.env.DRUPAL_CLIENT_SECRET as string,
64-
},
65-
})
58+
const client = await getDrupalClient()
6659

6760
const nodeRouteQuery = graphql(
6861
`

starters/react-router/app/utils/auth.server.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

starters/react-router/app/utils/client.server.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
This file is optional since we are only using the fetch exchange.
3+
Added to the starter to show how to configure exchanges in a Drupal Vite project.
4+
You can remove this file if you are not using any other exchanges.
5+
*/
6+
import { DrupalDecoupledConfig } from 'drupal-vite'
7+
import { fetchExchange } from '@urql/core'
8+
9+
export default {
10+
exchanges: [fetchExchange],
11+
} satisfies DrupalDecoupledConfig

starters/react-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"class-variance-authority": "^0.7.1",
2929
"clsx": "^2.1.1",
3030
"composable-functions": "^5.0.0",
31-
"drupal-auth-client": "^1.0",
3231
"drupal-decoupled": "^0.2.2",
32+
"drupal-vite": "^0.0.2",
3333
"gql.tada": "^1.8.10",
3434
"isbot": "^5.1.17",
3535
"lucide-react": "^0.474.0",

starters/react-router/react-router.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default {
44
ssr: true,
55
future: {
66
unstable_viteEnvironmentApi: true,
7+
unstable_optimizeDeps: true,
78
},
89
} satisfies Config

starters/react-router/vite.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ import { reactRouter } from '@react-router/dev/vite'
22
import tailwindcss from '@tailwindcss/vite'
33
import { defineConfig } from 'vite'
44
import tsconfigPaths from 'vite-tsconfig-paths'
5+
import { drupal } from 'drupal-vite'
56

67
const isStorybook = process.argv[1]?.includes('storybook')
78
export default defineConfig({
8-
plugins: [tailwindcss(), !isStorybook && reactRouter(), tsconfigPaths()],
9+
plugins: [
10+
tailwindcss(),
11+
!isStorybook && reactRouter(),
12+
drupal({
13+
drupalUrl: 'DRUPAL_AUTH_URI',
14+
}),
15+
tsconfigPaths(),
16+
],
917
})

0 commit comments

Comments
 (0)