@vertesia/create-plugin 0.76.0 → 0.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertesia/create-plugin",
3
- "version": "0.76.0",
3
+ "version": "0.78.0",
4
4
  "description": "Initialize a Vertesia plugin package",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,26 @@
1
+
2
+ let _usePluginAssets = true;
3
+
4
+ export function setUsePluginAssets(usePluginAssets: boolean) {
5
+ _usePluginAssets = usePluginAssets
6
+ }
7
+
8
+ /**
9
+ * Correctly resolve the URL to an asset so that it works in dev mode but also in prod as a standalone app or plugin.
10
+ * Assets must be put inside /public/assets folder so the given `path` will be resolved as /assets/path in the right context
11
+ * @param path
12
+ */
13
+ export function useAsset(path: string) {
14
+ if (path.startsWith('/')) {
15
+ path = path.substring(1);
16
+ } else if (path.startsWith('./')) {
17
+ path = path.substring(2);
18
+ }
19
+ if (_usePluginAssets) {
20
+ // the plugin.js file is in lib/ directory and we need to serve from assets/ directory
21
+ path = `../assets/${path}`;
22
+ return new URL(path, import.meta.url).href;
23
+ } else {
24
+ return `/assets/${path}`;
25
+ }
26
+ }
@@ -6,6 +6,9 @@ import './index.css'
6
6
  import { RouterProvider } from '@vertesia/ui/router'
7
7
  import { App } from './app'
8
8
  import "./env"
9
+ import { setUsePluginAssets } from './assets'
10
+
11
+ setUsePluginAssets(false);
9
12
 
10
13
  createRoot(document.getElementById('root')!).render(
11
14
  <StrictMode>
@@ -1,11 +1,15 @@
1
+ import { PortalContainerProvider } from "@vertesia/ui/core";
1
2
  import { App } from "./app";
3
+
2
4
  /**
3
5
  * Export the plugin component.
4
6
  */
5
7
  export default function ${ PluginComponent } ({ slot }: { slot: string }) {
6
8
  if (slot === "page") {
7
9
  return (
8
- <App />
10
+ <PortalContainerProvider>
11
+ <App />
12
+ </PortalContainerProvider>
9
13
  );
10
14
  } else {
11
15
  console.warn('No component found for slot', slot);
@@ -5,21 +5,26 @@ import react from '@vitejs/plugin-react';
5
5
  import { defineConfig, type ConfigEnv, type UserConfig } from 'vite';
6
6
  import serveStatic from "vite-plugin-serve-static";
7
7
 
8
+
8
9
  /**
9
- * List of external dependencies that should not be bundled when
10
- * buildiong the plugin library
10
+ * List of dependencies that must be bundled in the plugin bundle
11
11
  */
12
- const EXTERNALS = [
13
- 'react',
14
- 'react-dom',
15
- 'react/jsx-runtime',
16
- 'react-dom/client',
17
- '@vertesia/common',
18
- '@vertesia/ui',
19
- /^@vertesia\/ui\/.*/,
20
- // add any other external dependencies here
12
+ const INTERNALS: (string | RegExp)[] = [
21
13
  ];
22
14
 
15
+ function isExternal(id: string) {
16
+ // If it matches INTERNALS → bundle it
17
+ if (INTERNALS.some(pattern =>
18
+ pattern instanceof RegExp ? pattern.test(id) : id === pattern
19
+ )) {
20
+ return false;
21
+ }
22
+
23
+ // Otherwise → treat all bare imports (node_modules deps) as external
24
+ return !id.startsWith('.') && !id.startsWith('/') && !id.startsWith('@/') && !id.startsWith('virtual:');
25
+ }
26
+
27
+
23
28
  /**
24
29
  * if you want to debug vertesia ui sources define a relative path to the vertesia ui package root
25
30
  */
@@ -71,7 +76,7 @@ function defineLibConfig({ command }: ConfigEnv): UserConfig {
71
76
  minify: true,
72
77
  sourcemap: true,
73
78
  rollupOptions: {
74
- external: EXTERNALS,
79
+ external: isExternal,
75
80
  }
76
81
  }
77
82
  }