feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334)

This commit is contained in:
Kasper Fabricius Kristensen
2023-03-03 10:09:16 +01:00
committed by GitHub
parent d6b1ad1ccd
commit 40de54b010
928 changed files with 85441 additions and 384 deletions

View File

@@ -0,0 +1,5 @@
import { Base } from "../types"
export const formatBase = <T extends string>(base: T): Base<T> => {
return `/${base}/`
}

View File

@@ -0,0 +1,76 @@
import react from "@vitejs/plugin-react"
import { resolve } from "path"
import { BuildOptions, InlineConfig } from "vite"
import { AdminBuildConfig } from "../types"
import { formatBase } from "./format-base"
export const getCustomViteConfig = (config: AdminBuildConfig): InlineConfig => {
const { globals = {}, build = {} } = config
const uiPath = resolve(__dirname, "..", "..", "ui")
const globalReplacements = () => {
const base = globals.base || "app"
let backend = "/"
if (globals.backend) {
try {
// Test if the backend is a valid URL
new URL(globals.backend)
backend = globals.backend
} catch (_e) {
throw new Error(
`The provided backend URL is not valid: ${globals.backend}. Please provide a valid URL (e.g. https://my-medusa-server.com).`
)
}
}
return {
__BASE__: JSON.stringify(`/${base}`),
__MEDUSA_BACKEND_URL__: JSON.stringify(backend),
}
}
const buildConfig = (): BuildOptions => {
const { outDir } = build
let destDir: string
if (!outDir) {
/**
* Default build directory is at the root of the `@medusajs/admin-ui` package.
*/
destDir = resolve(__dirname, "..", "..", "build")
} else {
/**
* If a custom build directory is specified, it is resolved relative to the
* current working directory.
*/
destDir = resolve(process.cwd(), outDir)
}
return {
outDir: destDir,
emptyOutDir: true,
}
}
return {
plugins: [react()],
root: uiPath,
mode: "production",
base: formatBase(globals.base),
define: globalReplacements(),
build: buildConfig(),
resolve: {
alias: {
"@tanstack/react-query": resolve(
require.resolve("@tanstack/react-query")
),
},
},
clearScreen: false,
logLevel: "error",
}
}

View File

@@ -0,0 +1,2 @@
export * from "./format-base"
export * from "./get-custom-vite-config"