@mlut/plugins 1.0.1 → 1.0.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.
- package/dist/index.js +15 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -14,10 +14,12 @@ export const unplugin = createUnplugin((options, meta) => {
|
|
|
14
14
|
const cwd = process.cwd();
|
|
15
15
|
const pluginName = 'unplugin-mlut';
|
|
16
16
|
const finalOptions = { output: '' };
|
|
17
|
-
|
|
17
|
+
let inputPath = options.input && path.resolve(cwd, options.input);
|
|
18
18
|
let outputPath = '';
|
|
19
|
+
let viteWatchOutputPath = '';
|
|
19
20
|
let lastCompiledCss = '';
|
|
20
21
|
const isWebpack = meta.framework === 'webpack';
|
|
22
|
+
const isWindows = process.platform === 'win32';
|
|
21
23
|
let isVite = false;
|
|
22
24
|
let isViteWatch = false;
|
|
23
25
|
const writeCssFile = async () => {
|
|
@@ -57,6 +59,13 @@ export const unplugin = createUnplugin((options, meta) => {
|
|
|
57
59
|
await jitEngine.init([inputPath, inputContent]);
|
|
58
60
|
outputPath = path.resolve(cwd, finalOptions.output);
|
|
59
61
|
if (isViteWatch) {
|
|
62
|
+
if (isWindows) {
|
|
63
|
+
viteWatchOutputPath = path.isAbsolute(finalOptions.output) ?
|
|
64
|
+
finalOptions.output.replace(cwd, '') : finalOptions.output;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
viteWatchOutputPath = outputPath;
|
|
68
|
+
}
|
|
60
69
|
await fs.outputFile(outputPath, '').catch(() => undefined);
|
|
61
70
|
}
|
|
62
71
|
};
|
|
@@ -64,6 +73,7 @@ export const unplugin = createUnplugin((options, meta) => {
|
|
|
64
73
|
name: pluginName,
|
|
65
74
|
async config(_config, { command }) {
|
|
66
75
|
isVite = true;
|
|
76
|
+
inputPath = inputPath?.replaceAll('\\', '/');
|
|
67
77
|
if (command === 'serve') {
|
|
68
78
|
isViteWatch = true;
|
|
69
79
|
}
|
|
@@ -100,6 +110,9 @@ export const unplugin = createUnplugin((options, meta) => {
|
|
|
100
110
|
},
|
|
101
111
|
transform(code, id) {
|
|
102
112
|
jitEngine.putContent(id, code);
|
|
113
|
+
if (isViteWatch) {
|
|
114
|
+
debouncedWriteCssFile();
|
|
115
|
+
}
|
|
103
116
|
return null;
|
|
104
117
|
},
|
|
105
118
|
async transformIndexHtml(html, ctx) {
|
|
@@ -111,7 +124,7 @@ export const unplugin = createUnplugin((options, meta) => {
|
|
|
111
124
|
tags: [
|
|
112
125
|
{
|
|
113
126
|
tag: 'link',
|
|
114
|
-
attrs: { rel: 'stylesheet', href:
|
|
127
|
+
attrs: { rel: 'stylesheet', href: viteWatchOutputPath },
|
|
115
128
|
},
|
|
116
129
|
],
|
|
117
130
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlut/plugins",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "mlut plugins for Rollup, Vite and Webpack",
|
|
5
5
|
"author": "mr150",
|
|
6
6
|
"type": "module",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"typescript": "^4.8.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@mlut/core": "^2.
|
|
54
|
+
"@mlut/core": "^2.1.0",
|
|
55
55
|
"fs-extra": "^11.2.0",
|
|
56
56
|
"unplugin": "^1.10.1"
|
|
57
57
|
}
|