Loader (cms-client.js), submodule-aware editor source path, build:watch
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e0bf1e88e
commit
cb7a7a1fab
8 files changed
+158
-7
No files matched your search
+30
-2
@@ -1,12 +1,24 @@
|
||||
import { defineConfig, loadEnv, type UserConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'node:path'
|
||||
import { existsSync } from 'node:fs'
|
||||
import { cmsLivePlugin } from './vite/live'
|
||||
import { cmsMockPlugin } from './vite/mock'
|
||||
|
||||
export default defineConfig(({ command, mode }): UserConfig => {
|
||||
const env = { ...loadEnv(mode, process.cwd(), ''), ...process.env } as Record<string, string>
|
||||
const editorSrc = path.resolve(env.CMS_EDITOR_SRC || '../ecommerce/backoffice/web/packages/cms-editor/src')
|
||||
// Shared @k6n/cms-editor sources. As a submodule of the ecommerce monorepo the
|
||||
// backoffice is a sibling; a standalone checkout sits next to ../ecommerce.
|
||||
const editorSrc = path.resolve(
|
||||
env.CMS_EDITOR_SRC ||
|
||||
['../backoffice/web/packages/cms-editor/src', '../ecommerce/backoffice/web/packages/cms-editor/src', './.cms-editor/src'].find((p) =>
|
||||
existsSync(path.resolve(p)),
|
||||
) ||
|
||||
'../backoffice/web/packages/cms-editor/src',
|
||||
)
|
||||
// CMS_ONPAGE_OUT: build straight into an instance's public/ (dev launcher --watch).
|
||||
const outDir = env.CMS_ONPAGE_OUT ? path.resolve(env.CMS_ONPAGE_OUT) : 'dist'
|
||||
const emptyOutDir = !env.CMS_ONPAGE_OUT
|
||||
const common: UserConfig = {
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
@@ -23,6 +35,21 @@ export default defineConfig(({ command, mode }): UserConfig => {
|
||||
},
|
||||
} as UserConfig
|
||||
|
||||
if (command === 'build' && mode === 'loader') {
|
||||
// /editor/cms-client.js: the stable URL page templates reference. Classic
|
||||
// script (IIFE), tiny; imports the editor bundle only for editors.
|
||||
return {
|
||||
...common,
|
||||
define: { 'process.env.NODE_ENV': '"production"' },
|
||||
build: {
|
||||
outDir,
|
||||
emptyOutDir: false,
|
||||
lib: { entry: 'src/loader.ts', name: 'CMSClient', formats: ['iife'], fileName: () => 'cms-client.js' },
|
||||
sourcemap: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (command === 'build') {
|
||||
// The artifact served at /editor/onpage-editor.js. One self-contained file;
|
||||
// only loaded when the preview cookie is present (see src/main.ts).
|
||||
@@ -30,7 +57,8 @@ export default defineConfig(({ command, mode }): UserConfig => {
|
||||
...common,
|
||||
define: { 'process.env.NODE_ENV': '"production"' },
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
outDir,
|
||||
emptyOutDir,
|
||||
lib: { entry: 'src/main.ts', formats: ['es'], fileName: () => 'onpage-editor.js' },
|
||||
sourcemap: true,
|
||||
cssCodeSplit: false,
|
||||
|
||||
Reference in new issue
Block a user