@ws-ui/vite-plugins 1.8.1 → 1.8.2

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.
@@ -1,19 +1,51 @@
1
+ import * as fs from 'fs';
1
2
  export default function standaloneEditorPlugin() {
3
+ let config;
4
+ let cssContent = '';
5
+ const name = 'standaline-editor-plugin';
6
+ const standaloneCssPath = '@ws-ui/webform-editor/dist/standalone.css';
2
7
  return {
3
- name: 'standalone-editor-plugin',
8
+ name,
9
+ // Get the final configuration, including the resolved root
10
+ configResolved(resolvedConfig) {
11
+ config = resolvedConfig;
12
+ },
13
+ // Use the buildStart hook to read the file content once.
14
+ // This hook runs after configResolved, but before the dev server starts transforming HTML.
15
+ async buildStart() {
16
+ // Only execute this logic in development mode ('serve')
17
+ if (config.command !== 'serve') {
18
+ return;
19
+ }
20
+ // Vite uses bare imports like this by default, so we can try to resolve it
21
+ try {
22
+ // Resolve the bare module specifier to its real file system path
23
+ // We use the same resolution logic Vite uses for modules
24
+ const resolved = await config.createResolver({ asSrc: false })(standaloneCssPath);
25
+ if (resolved && fs.existsSync(resolved)) {
26
+ // Read the content of the CSS file
27
+ cssContent = fs.readFileSync(resolved, 'utf-8');
28
+ console.log(`[${name}] Successfully read CSS content from: ${resolved}`);
29
+ }
30
+ else {
31
+ console.error(`[${name}] Could not resolve or find the CSS file: ${standaloneCssPath}`);
32
+ }
33
+ }
34
+ catch (e) {
35
+ console.error(`[${name}] Error reading CSS file:`, e);
36
+ }
37
+ },
38
+ // Inject the content into the HTML
4
39
  transformIndexHtml(html, ctx) {
5
- // Check if the Vite dev server context exists.
6
- // This is true for 'vite dev' and false for 'vite build'.
7
- if (ctx.server) {
40
+ // Check if we are in dev mode and have content to inject
41
+ if (ctx.server && cssContent) {
8
42
  return [
9
43
  {
10
- tag: 'link',
44
+ tag: 'style',
11
45
  attrs: {
12
- rel: 'stylesheet',
13
- // Vite will resolve this path to the correct URL in node_modules/
14
- href: '@ws-ui/webform-editor/dist/standalone.css',
46
+ type: 'text/css',
15
47
  },
16
- // Inject right before the closing </head> tag for early loading
48
+ children: cssContent,
17
49
  injectTo: 'head-prepend',
18
50
  },
19
51
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ws-ui/vite-plugins",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -21,4 +21,4 @@
21
21
  "dependencies": {
22
22
  "import-meta-resolve": "^4.1.0"
23
23
  }
24
- }
24
+ }