@ws-ui/vite-plugins 1.8.3 → 1.8.5
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,27 +1,27 @@
|
|
|
1
1
|
import { rmSync, readdirSync, statSync, existsSync } from 'node:fs';
|
|
2
|
-
import
|
|
2
|
+
import { join } from 'node:path';
|
|
3
3
|
export default function excludeFilesPlugin(config) {
|
|
4
4
|
return {
|
|
5
5
|
name: 'exclude-files',
|
|
6
6
|
closeBundle() {
|
|
7
7
|
const out = process.env.VITE_BUILD_TARGET || '';
|
|
8
|
-
const baseDir =
|
|
8
|
+
const baseDir = join(process.cwd(), out);
|
|
9
9
|
// Remove exclude files/folders outside of all rule targets
|
|
10
10
|
const ruleTargets = config.rules.map((r) => r.target.replace(/\/$/, ''));
|
|
11
11
|
for (const name of readdirSync(baseDir)) {
|
|
12
12
|
if (ruleTargets.includes(name))
|
|
13
13
|
continue; // skip target folders
|
|
14
14
|
if (config.exclude.includes(name)) {
|
|
15
|
-
rmSync(
|
|
15
|
+
rmSync(join(baseDir, name), { recursive: true, force: true });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
// Apply each rule: inside target folder, keep matching files, delete others
|
|
19
19
|
for (const rule of config.rules) {
|
|
20
|
-
const targetDir =
|
|
20
|
+
const targetDir = join(baseDir, rule.target);
|
|
21
21
|
if (!existsSync(targetDir))
|
|
22
22
|
continue;
|
|
23
23
|
for (const file of readdirSync(targetDir)) {
|
|
24
|
-
const fp =
|
|
24
|
+
const fp = join(targetDir, file);
|
|
25
25
|
if (statSync(fp).isDirectory()) {
|
|
26
26
|
rmSync(fp, { recursive: true, force: true });
|
|
27
27
|
continue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url';
|
|
2
2
|
import monacoEditorPlugin from './vite-plugin-monaco-editor';
|
|
3
|
-
|
|
3
|
+
import standaloneEditorPlugin from './standalone-editor-plugin';
|
|
4
|
+
export { importMetaUrlPlugin, monacoEditorPlugin, standaloneEditorPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url';
|
|
2
2
|
import monacoEditorPlugin from './vite-plugin-monaco-editor';
|
|
3
|
-
|
|
3
|
+
import standaloneEditorPlugin from './standalone-editor-plugin';
|
|
4
|
+
export { importMetaUrlPlugin, monacoEditorPlugin, standaloneEditorPlugin };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
export default function standaloneEditorPlugin() {
|
|
3
|
+
let config;
|
|
4
|
+
let cssContent = '';
|
|
5
|
+
const name = 'standalone-editor-plugin';
|
|
6
|
+
const standaloneCssPath = '@ws-ui/webform-editor/dist/standalone.css';
|
|
7
|
+
return {
|
|
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
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.error(`[${name}] Could not resolve or find the CSS file: ${standaloneCssPath}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.error(`[${name}] Error reading CSS file:`, e);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
// Inject the content into the HTML
|
|
38
|
+
transformIndexHtml(html, ctx) {
|
|
39
|
+
// Check if we are in dev mode and have content to inject
|
|
40
|
+
if (ctx.server && cssContent) {
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
tag: 'style',
|
|
44
|
+
attrs: {
|
|
45
|
+
type: 'text/css',
|
|
46
|
+
},
|
|
47
|
+
children: cssContent,
|
|
48
|
+
injectTo: 'head-prepend',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
return html;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|