vite-plugin-prism-design 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -111,8 +111,8 @@ function prismDesign(options = {}) {
111
111
  agentProcess = null;
112
112
  });
113
113
  const actualPort = await portPromise;
114
- agentUrl = `http://localhost:${actualPort}`;
115
- config.logger.info(`[PrismDesign] Agent ready at ${agentUrl}`);
114
+ agentUrl = `__AGENT_PORT__:${actualPort}`;
115
+ config.logger.info(`[PrismDesign] Agent ready on port ${actualPort}`);
116
116
  } else {
117
117
  config.logger.warn("[PrismDesign] Agent CLI not found. Install prism-design-agent or run agent manually.");
118
118
  config.logger.info("[PrismDesign] Widget will show connection form for manual URL input.");
@@ -130,10 +130,19 @@ function prismDesign(options = {}) {
130
130
  },
131
131
  transformIndexHtml() {
132
132
  const initOptions = {};
133
- if (agentUrl) initOptions.agentUrl = agentUrl;
134
133
  if (position !== "bottom-right") initOptions.position = position;
135
134
  if (locale) initOptions.locale = locale;
136
- const optionsJson = JSON.stringify(initOptions);
135
+ let initScript;
136
+ if (agentUrl.startsWith("__AGENT_PORT__:")) {
137
+ const port = agentUrl.split(":")[1];
138
+ const optionsJson = JSON.stringify(initOptions);
139
+ initScript = `(function(){var o=${optionsJson};o.agentUrl="http://"+location.hostname+":${port}";PrismDesignWidget.init(o)})();`;
140
+ } else if (agentUrl) {
141
+ initOptions.agentUrl = agentUrl;
142
+ initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
143
+ } else {
144
+ initScript = `PrismDesignWidget.init(${JSON.stringify(initOptions)});`;
145
+ }
137
146
  return [
138
147
  {
139
148
  tag: "script",
@@ -142,7 +151,7 @@ function prismDesign(options = {}) {
142
151
  },
143
152
  {
144
153
  tag: "script",
145
- children: `PrismDesignWidget.init(${optionsJson});`,
154
+ children: initScript,
146
155
  injectTo: "body"
147
156
  }
148
157
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-prism-design",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",