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

Support custom VitePlugins in the Tina config #4388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/young-donuts-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tinacms/schema-tools': minor
'@tinacms/cli': minor
---

Support custom VitePlugins in the Tina config. This is intended to provide advanced ways to customise the Admin Portal build output. One example use case is to provide a custom tailwind plugin (similar to the TinaTailwind plugin) and build CSS for any custom React components we load in the Tina Admin portal via Tina field plugins. Otherwise the Tailwind classes we use in Tina field plugins do not appear in the Tina Admin portal CSS.
3 changes: 3 additions & 0 deletions packages/@tinacms/cli/src/next/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path'
import os from 'os'
import * as esbuild from 'esbuild'
import type { Loader } from 'esbuild'
import type { Plugin } from 'vite'
import { Config } from '@tinacms/schema-tools'
import * as dotenv from 'dotenv'
import normalizePath from 'normalize-path'
Expand Down Expand Up @@ -55,6 +56,7 @@ export class ConfigManager {
spaRootPath: string
spaMainPath: string
spaHTMLPath: string
vitePlugins?: Array<(configManager: ConfigManager) => Plugin>
tinaGraphQLVersionFromCLI?: string
legacyNoSDK?: boolean
watchList?: string[]
Expand Down Expand Up @@ -261,6 +263,7 @@ export class ConfigManager {
)
this.spaMainPath = require.resolve('@tinacms/app')
this.spaRootPath = path.join(this.spaMainPath, '..', '..')
this.vitePlugins = this.config.ui?.vitePlugins
// =================
// End of paths that depend on the config file
}
Expand Down
4 changes: 4 additions & 0 deletions packages/@tinacms/cli/src/next/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export const createConfig = async ({
}
}
})
const customPlugins: Plugin[] = configManager.vitePlugins
? configManager.vitePlugins.map((pluginFn) => pluginFn(configManager))
: []

const staticMediaPath: string = path.join(
configManager.generatedFolderPath,
Expand Down Expand Up @@ -251,6 +254,7 @@ export const createConfig = async ({
}),
splitVendorChunkPlugin(),
tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
...customPlugins,
...plugins,
],
}
Expand Down
1 change: 1 addition & 0 deletions packages/@tinacms/schema-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"jest": "^29.5.0",
"react": "17.0.2",
"typescript": "4.3.5",
"vite": "^4.3.9",
"yup": "^0.32.0"
},
"peerDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/@tinacms/schema-tools/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FC } from 'react'
import type React from 'react'
import type { Plugin } from 'vite'

type Meta = {
active?: boolean
Expand Down Expand Up @@ -555,6 +556,13 @@ export interface Config<
* [more info](https://vercel.com/docs/concepts/deployments/generated-urls#url-with-git-branch)
*/
previewUrl: (context: { branch: string }) => { url: string }
/**
* An array of functions that return a vite Plugin to be loaded when building the Tina Admin Portal.
* One use case for this is to provide a custom tailwind plugin (similar to the TinaTailwind plugin)
* and build CSS for any new components you load in the Tina Admin portal (e.g. Tina field plugins).
* Otherwise Tailwind classes used in Tina field plugins may not appear in the Tina Admin portal CSS
*/
vitePlugins?: Array<(configManager: any) => Plugin>
}
/**
* Configurations for the autogenerated GraphQL HTTP client
Expand Down
Loading
Loading