feat(admin-bundler,admin-vite-plugin,medusa): Add support for loading Admin Extensions from plugins (#10869)
Should not be merged before https://github.com/medusajs/medusa/pull/10895 **What** - Introduces a new `plugin` command to `admin-bundler`, currently not used anywhere but will be called from `medusa build:plugin` - Discovers plugins with extensions and add passes the to `admin-vite-plugin`. - Updates `admin-vite-plugin` so its able to read built admin extensions. Resolves CMRC-830, CMRC-839
This commit is contained in:
@@ -2,7 +2,6 @@ import { VIRTUAL_MODULES } from "@medusajs/admin-shared"
|
||||
import path from "path"
|
||||
import { Config } from "tailwindcss"
|
||||
import type { InlineConfig } from "vite"
|
||||
|
||||
import { BundlerOptions } from "../types"
|
||||
|
||||
export async function getViteConfig(
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { readFileSync } from "fs"
|
||||
import { glob } from "glob"
|
||||
import path from "path"
|
||||
import { UserConfig } from "vite"
|
||||
|
||||
export async function plugin() {
|
||||
const vite = await import("vite")
|
||||
const entries = await glob("src/admin/**/*.{ts,tsx,js,jsx}")
|
||||
|
||||
const entryPoints = entries.reduce((acc, entry) => {
|
||||
// Convert src/admin/routes/brands/page.tsx -> admin/routes/brands/page
|
||||
const outPath = entry
|
||||
.replace(/^src\//, "")
|
||||
.replace(/\.(ts|tsx|js|jsx)$/, "")
|
||||
|
||||
acc[outPath] = path.resolve(process.cwd(), entry)
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(path.resolve(process.cwd(), "package.json"), "utf-8")
|
||||
)
|
||||
const external = new Set([
|
||||
...Object.keys(pkg.dependencies || {}),
|
||||
...Object.keys(pkg.peerDependencies || {}),
|
||||
"react",
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react-router-dom",
|
||||
"@medusajs/admin-sdk",
|
||||
])
|
||||
|
||||
const pluginConfig: UserConfig = {
|
||||
build: {
|
||||
lib: {
|
||||
entry: entryPoints,
|
||||
formats: ["es"],
|
||||
},
|
||||
minify: false,
|
||||
outDir: path.resolve(process.cwd(), "dist"),
|
||||
rollupOptions: {
|
||||
external: [...external],
|
||||
output: {
|
||||
globals: {
|
||||
react: "React",
|
||||
"react-dom": "React-dom",
|
||||
"react/jsx-runtime": "react/jsx-runtime",
|
||||
},
|
||||
preserveModules: true,
|
||||
entryFileNames: `[name].js`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
await vite.build(pluginConfig)
|
||||
}
|
||||
Reference in New Issue
Block a user