@lntvow/vite-plugin 1.0.8 → 1.1.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/LICENSE +21 -0
- package/README.md +3 -1
- package/dist/index.cjs +23 -102
- package/dist/index.d.cts +67 -8
- package/dist/index.d.ts +67 -8
- package/dist/index.mjs +24 -0
- package/package.json +39 -13
- package/dist/index.js +0 -65
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 lntvow
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,103 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";var w=Object.create;var c=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var E=(o,n)=>{for(var t in n)c(o,t,{get:n[t],enumerable:!0})},v=(o,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of R(n))!z.call(o,e)&&e!==t&&c(o,e,{get:()=>n[e],enumerable:!(r=P(n,e))||r.enumerable});return o};var m=(o,n,t)=>(t=o!=null?w(S(o)):{},v(n||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),q=o=>v(c({},"__esModule",{value:!0}),o);var H={};E(H,{vitePluginEnvRibbon:()=>k,vitePluginHtml:()=>j,vitePluginLog:()=>L});module.exports=q(H);var s=require("path"),h=require("fs"),l=m(require("dayjs"),1),x=m(require("dayjs/plugin/timezone.js"),1),$=m(require("dayjs/plugin/utc.js"),1);l.default.extend($.default);l.default.extend(x.default);function L(o={}){let{name:n="LNTVOW_VERSION"}=o,{version:t}=o;if(!t)try{let e=(0,h.readFileSync)((0,s.resolve)(process.cwd(),"package.json"),"utf8");t=JSON.parse(e).version}catch(e){t="version is missing",console.log("error: ",e)}let r=[(0,s.resolve)(process.cwd(),"src/main.ts"),(0,s.resolve)(process.cwd(),"src/main.js")];return{name:"vite-plugin-logs",transform(e,f){if(r.includes((0,s.normalize)(f))){let p=(0,l.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
|
|
2
|
+
${e}
|
|
29
3
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const packageJsonContent = import_node_fs.default.readFileSync(import_node_path.default.resolve(process.cwd(), "package.json"), "utf8");
|
|
53
|
-
version = JSON.parse(packageJsonContent).version;
|
|
54
|
-
} catch (e) {
|
|
55
|
-
(0, import_utils.throwError)("vitePluginLogs", "package.json not found");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
name: "vite-plugin-logs",
|
|
60
|
-
transform(code, id) {
|
|
61
|
-
if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
|
|
62
|
-
const time = (0, import_dayjs.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
|
|
63
|
-
return {
|
|
64
|
-
code: `
|
|
65
|
-
|
|
66
|
-
import { log as vitePluginLogs } from '@lntvow/utils';
|
|
67
|
-
|
|
68
|
-
${code}
|
|
69
|
-
|
|
70
|
-
localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
|
|
71
|
-
vitePluginLogs('version', '${time}', '${version}')
|
|
72
|
-
|
|
73
|
-
`
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/vite-plugin-html.ts
|
|
81
|
-
var import_vite = require("vite");
|
|
82
|
-
function vitePluginHtml() {
|
|
83
|
-
let env = {};
|
|
84
|
-
return {
|
|
85
|
-
name: "vite-plugin-html",
|
|
86
|
-
enforce: "pre",
|
|
87
|
-
config(config, { mode }) {
|
|
88
|
-
env = (0, import_vite.loadEnv)(mode, process.cwd());
|
|
89
|
-
},
|
|
90
|
-
transformIndexHtml(html) {
|
|
91
|
-
Object.keys(env).forEach((key) => {
|
|
92
|
-
const regex = new RegExp(`%${key}%`, "g");
|
|
93
|
-
html = html.replace(regex, env[key]);
|
|
94
|
-
});
|
|
95
|
-
return html;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
-
0 && (module.exports = {
|
|
101
|
-
vitePluginHtml,
|
|
102
|
-
vitePluginLog
|
|
103
|
-
});
|
|
4
|
+
localStorage.setItem('${n}', JSON.stringify(['${p}', '${t}']))
|
|
5
|
+
console.log('[Log] version: ', ['${p}', '${t}']);
|
|
6
|
+
`}}}}}var b=require("vite");function j(){let o={};return{name:"vite-plugin-html",enforce:"pre",config(n,{mode:t}){o=(0,b.loadEnv)(t,process.cwd())},transformIndexHtml(n){return Object.keys(o).forEach(t=>{let r=new RegExp(`%${t}%`,"g");n=n.replace(r,o[t])}),n}}}function k(o={}){let{width:n=150,height:t=20,fontSize:r=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:f="#fff",position:p="top-right",envMap:O={}}=o,i;return{name:"vite-plugin-env-ribbon",transformIndexHtml(a){if(console.log("mode: ",i),i==="production")return a;let d=O[i]||i;if(!d)return a;let g=p==="top-left",y=g?`translate(-${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${n/Math.sqrt(2)}px) rotate(45deg)`,M=`
|
|
7
|
+
position: fixed;
|
|
8
|
+
width: ${n}px;
|
|
9
|
+
height: ${t}px;
|
|
10
|
+
background: ${e};
|
|
11
|
+
color: ${f};
|
|
12
|
+
font-size: ${r}px;
|
|
13
|
+
line-height: ${t}px;
|
|
14
|
+
transform: ${y};
|
|
15
|
+
transform-origin: ${g?"left top":"right top"};
|
|
16
|
+
top: 0;
|
|
17
|
+
right: ${g?"auto":"0"};
|
|
18
|
+
left: ${g?"0":"auto"};
|
|
19
|
+
z-index: 9999;
|
|
20
|
+
text-align: center;
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
user-select: none;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
`;return{html:a,tags:[{tag:"div",attrs:{style:M.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":i},children:d,injectTo:"body"}]}},configResolved(a){i=a.mode}}}0&&(module.exports={vitePluginEnvRibbon,vitePluginHtml,vitePluginLog});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
|
|
3
|
-
declare function vitePluginLog(options?:
|
|
4
|
-
interface
|
|
3
|
+
declare function vitePluginLog(options?: LogOptions): PluginOption;
|
|
4
|
+
interface LogOptions {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @default LNTVOW_VERSION
|
|
6
|
+
* localStorage key
|
|
7
|
+
* @default 'LNTVOW_VERSION'
|
|
8
8
|
*/
|
|
9
9
|
name?: string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* 版本号
|
|
12
12
|
* @default 默认读取package.json的version
|
|
13
13
|
*/
|
|
14
14
|
version?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
declare function vitePluginHtml():
|
|
17
|
+
declare function vitePluginHtml(): PluginOption;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* This Vite plugin injects a diagonal environment ribbon into the built HTML page.
|
|
21
|
+
* The ribbon displays the current environment (such as development, uat, pre, etc.)
|
|
22
|
+
* in the top-left or top-right corner of the page, similar to environment tags
|
|
23
|
+
* seen in some mobile app demos.
|
|
24
|
+
*
|
|
25
|
+
* The ribbon will NOT be injected when the current mode is 'production'.
|
|
26
|
+
*
|
|
27
|
+
* You can customize the ribbon's width, height, font size, background color, text color,
|
|
28
|
+
* position, and environment label mapping via plugin options.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
|
|
32
|
+
*
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [
|
|
35
|
+
* vitePluginEnvRibbon(),
|
|
36
|
+
* ],
|
|
37
|
+
* })
|
|
38
|
+
*/
|
|
39
|
+
declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
|
|
40
|
+
interface EnvRibbonOptions {
|
|
41
|
+
/**
|
|
42
|
+
* The height of the banner.
|
|
43
|
+
* @default 20
|
|
44
|
+
*/
|
|
45
|
+
height?: number;
|
|
46
|
+
/**
|
|
47
|
+
* The width of the banner.
|
|
48
|
+
* @default 150
|
|
49
|
+
*/
|
|
50
|
+
width?: number;
|
|
51
|
+
/**
|
|
52
|
+
* The font size of the banner text.
|
|
53
|
+
* @default 12
|
|
54
|
+
*/
|
|
55
|
+
fontSize?: number;
|
|
56
|
+
/**
|
|
57
|
+
* The background color of the banner.
|
|
58
|
+
* @default 'hsla(0, 100%, 33%, 0.733)'
|
|
59
|
+
*/
|
|
60
|
+
backgroundColor?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The text color of the banner.
|
|
63
|
+
* @default '#fff'
|
|
64
|
+
*/
|
|
65
|
+
color?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The position of the banner on the screen.
|
|
68
|
+
* @default 'top-right'
|
|
69
|
+
*/
|
|
70
|
+
position?: 'top-right' | 'top-left';
|
|
71
|
+
/**
|
|
72
|
+
* The mapping of environment modes to display labels.
|
|
73
|
+
* @default {}
|
|
74
|
+
*/
|
|
75
|
+
envMap?: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
|
|
3
|
-
declare function vitePluginLog(options?:
|
|
4
|
-
interface
|
|
3
|
+
declare function vitePluginLog(options?: LogOptions): PluginOption;
|
|
4
|
+
interface LogOptions {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @default LNTVOW_VERSION
|
|
6
|
+
* localStorage key
|
|
7
|
+
* @default 'LNTVOW_VERSION'
|
|
8
8
|
*/
|
|
9
9
|
name?: string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* 版本号
|
|
12
12
|
* @default 默认读取package.json的version
|
|
13
13
|
*/
|
|
14
14
|
version?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
declare function vitePluginHtml():
|
|
17
|
+
declare function vitePluginHtml(): PluginOption;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* This Vite plugin injects a diagonal environment ribbon into the built HTML page.
|
|
21
|
+
* The ribbon displays the current environment (such as development, uat, pre, etc.)
|
|
22
|
+
* in the top-left or top-right corner of the page, similar to environment tags
|
|
23
|
+
* seen in some mobile app demos.
|
|
24
|
+
*
|
|
25
|
+
* The ribbon will NOT be injected when the current mode is 'production'.
|
|
26
|
+
*
|
|
27
|
+
* You can customize the ribbon's width, height, font size, background color, text color,
|
|
28
|
+
* position, and environment label mapping via plugin options.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { vitePluginEnvRibbon } from '@lntvow/vite-plugin'
|
|
32
|
+
*
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [
|
|
35
|
+
* vitePluginEnvRibbon(),
|
|
36
|
+
* ],
|
|
37
|
+
* })
|
|
38
|
+
*/
|
|
39
|
+
declare function vitePluginEnvRibbon(options?: EnvRibbonOptions): PluginOption;
|
|
40
|
+
interface EnvRibbonOptions {
|
|
41
|
+
/**
|
|
42
|
+
* The height of the banner.
|
|
43
|
+
* @default 20
|
|
44
|
+
*/
|
|
45
|
+
height?: number;
|
|
46
|
+
/**
|
|
47
|
+
* The width of the banner.
|
|
48
|
+
* @default 150
|
|
49
|
+
*/
|
|
50
|
+
width?: number;
|
|
51
|
+
/**
|
|
52
|
+
* The font size of the banner text.
|
|
53
|
+
* @default 12
|
|
54
|
+
*/
|
|
55
|
+
fontSize?: number;
|
|
56
|
+
/**
|
|
57
|
+
* The background color of the banner.
|
|
58
|
+
* @default 'hsla(0, 100%, 33%, 0.733)'
|
|
59
|
+
*/
|
|
60
|
+
backgroundColor?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The text color of the banner.
|
|
63
|
+
* @default '#fff'
|
|
64
|
+
*/
|
|
65
|
+
color?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The position of the banner on the screen.
|
|
68
|
+
* @default 'top-right'
|
|
69
|
+
*/
|
|
70
|
+
position?: 'top-right' | 'top-left';
|
|
71
|
+
/**
|
|
72
|
+
* The mapping of environment modes to display labels.
|
|
73
|
+
* @default {}
|
|
74
|
+
*/
|
|
75
|
+
envMap?: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type EnvRibbonOptions, type LogOptions, vitePluginEnvRibbon, vitePluginHtml, vitePluginLog };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{normalize as x,resolve as c}from"path";import{readFileSync as $}from"fs";import m from"dayjs";import b from"dayjs/plugin/timezone.js";import O from"dayjs/plugin/utc.js";m.extend(O);m.extend(b);function L(n={}){let{name:o="LNTVOW_VERSION"}=n,{version:t}=n;if(!t)try{let e=$(c(process.cwd(),"package.json"),"utf8");t=JSON.parse(e).version}catch(e){t="version is missing",console.log("error: ",e)}let i=[c(process.cwd(),"src/main.ts"),c(process.cwd(),"src/main.js")];return{name:"vite-plugin-logs",transform(e,g){if(i.includes(x(g))){let a=m().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");return{code:`
|
|
2
|
+
${e}
|
|
3
|
+
|
|
4
|
+
localStorage.setItem('${o}', JSON.stringify(['${a}', '${t}']))
|
|
5
|
+
console.log('[Log] version: ', ['${a}', '${t}']);
|
|
6
|
+
`}}}}}import{loadEnv as y}from"vite";function I(){let n={};return{name:"vite-plugin-html",enforce:"pre",config(o,{mode:t}){n=y(t,process.cwd())},transformIndexHtml(o){return Object.keys(n).forEach(t=>{let i=new RegExp(`%${t}%`,"g");o=o.replace(i,n[t])}),o}}}function C(n={}){let{width:o=150,height:t=20,fontSize:i=12,backgroundColor:e="hsla(0, 100%, 33%, 0.733)",color:g="#fff",position:a="top-right",envMap:d={}}=n,r;return{name:"vite-plugin-env-ribbon",transformIndexHtml(s){if(console.log("mode: ",r),r==="production")return s;let u=d[r]||r;if(!u)return s;let p=a==="top-left",v=p?`translate(-${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(-45deg)`:`translate(${t/Math.sqrt(2)}px, -${t/Math.sqrt(2)}px) translate(0, ${o/Math.sqrt(2)}px) rotate(45deg)`,h=`
|
|
7
|
+
position: fixed;
|
|
8
|
+
width: ${o}px;
|
|
9
|
+
height: ${t}px;
|
|
10
|
+
background: ${e};
|
|
11
|
+
color: ${g};
|
|
12
|
+
font-size: ${i}px;
|
|
13
|
+
line-height: ${t}px;
|
|
14
|
+
transform: ${v};
|
|
15
|
+
transform-origin: ${p?"left top":"right top"};
|
|
16
|
+
top: 0;
|
|
17
|
+
right: ${p?"auto":"0"};
|
|
18
|
+
left: ${p?"0":"auto"};
|
|
19
|
+
z-index: 9999;
|
|
20
|
+
text-align: center;
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
user-select: none;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
`;return{html:s,tags:[{tag:"div",attrs:{style:h.replace(/\s+/g," ").trim(),class:"vite-plugin-env-ribbon","data-env-ribbon":r},children:u,injectTo:"body"}]}},configResolved(s){r=s.mode}}}export{C as vitePluginEnvRibbon,I as vitePluginHtml,L as vitePluginLog};
|
package/package.json
CHANGED
|
@@ -1,31 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/vite-plugin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "vite
|
|
5
|
+
"description": "Collection of custom vite plugins",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vite-plugin"
|
|
8
|
+
],
|
|
6
9
|
"license": "MIT",
|
|
7
|
-
"
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/lntvow/vite-plugin.git"
|
|
13
|
+
},
|
|
8
14
|
"files": [
|
|
9
15
|
"dist"
|
|
10
16
|
],
|
|
11
|
-
"main": "dist/index.cjs",
|
|
12
|
-
"module": "dist/index.js",
|
|
13
17
|
"types": "dist/index.d.ts",
|
|
18
|
+
"main": "dist/index.cjs",
|
|
19
|
+
"module": "dist/index.mjs",
|
|
20
|
+
"exports": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.mjs"
|
|
24
|
+
},
|
|
14
25
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"dayjs": "^1.11.11"
|
|
26
|
+
"dayjs": "^1.11.13"
|
|
17
27
|
},
|
|
18
28
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
29
|
+
"@commitlint/cli": "^19.8.1",
|
|
30
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
31
|
+
"@lntvow/eslint-config": "^9.26.6",
|
|
32
|
+
"bumpp": "^10.2.0",
|
|
33
|
+
"commitizen": "^4.3.1",
|
|
34
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
35
|
+
"eslint": "^9.29.0",
|
|
36
|
+
"lint-staged": "^16.1.2",
|
|
37
|
+
"npm-run-all": "^4.1.5",
|
|
38
|
+
"prettier": "^3.6.1",
|
|
39
|
+
"simple-git-hooks": "^2.13.0",
|
|
40
|
+
"tsup": "^8.5.0",
|
|
41
|
+
"typescript": "^5.8.3"
|
|
21
42
|
},
|
|
22
43
|
"peerDependencies": {
|
|
23
|
-
"vite": ">=
|
|
44
|
+
"vite": ">=5.0.0"
|
|
24
45
|
},
|
|
25
46
|
"scripts": {
|
|
26
|
-
"
|
|
27
|
-
"commit": "git add . && git-cz && git push",
|
|
47
|
+
"postinstall": "simple-git-hooks",
|
|
28
48
|
"rimraf": "rimraf ./node_modules/",
|
|
29
|
-
"
|
|
49
|
+
"ncu": "ncu -u --reject @types/node && pnpm install",
|
|
50
|
+
"commit": "git add . && git-cz && pnpm release -y",
|
|
51
|
+
"release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
|
|
52
|
+
"lint:eslint": "eslint \"src/**/*.{js,jsx,ts,tsx,vue}\" --fix",
|
|
53
|
+
"lint:tsc": "tsc --noEmit",
|
|
54
|
+
"lint": "run-p lint:eslint lint:tsc",
|
|
55
|
+
"build": "tsup"
|
|
30
56
|
}
|
|
31
57
|
}
|
package/dist/index.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/vite-plugin-logs.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import dayjs from "dayjs";
|
|
5
|
-
import utc from "dayjs/plugin/utc";
|
|
6
|
-
import timezone from "dayjs/plugin/timezone";
|
|
7
|
-
import { throwError } from "@lntvow/utils";
|
|
8
|
-
dayjs.extend(utc);
|
|
9
|
-
dayjs.extend(timezone);
|
|
10
|
-
function vitePluginLog(options = {}) {
|
|
11
|
-
const { name = "LNTVOW_VERSION" } = options;
|
|
12
|
-
let { version } = options;
|
|
13
|
-
if (!version) {
|
|
14
|
-
try {
|
|
15
|
-
const packageJsonContent = fs.readFileSync(path.resolve(process.cwd(), "package.json"), "utf8");
|
|
16
|
-
version = JSON.parse(packageJsonContent).version;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
throwError("vitePluginLogs", "package.json not found");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
name: "vite-plugin-logs",
|
|
23
|
-
transform(code, id) {
|
|
24
|
-
if (id.endsWith("src/main.ts") || id.endsWith("src/main.js")) {
|
|
25
|
-
const time = dayjs().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss");
|
|
26
|
-
return {
|
|
27
|
-
code: `
|
|
28
|
-
|
|
29
|
-
import { log as vitePluginLogs } from '@lntvow/utils';
|
|
30
|
-
|
|
31
|
-
${code}
|
|
32
|
-
|
|
33
|
-
localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
|
|
34
|
-
vitePluginLogs('version', '${time}', '${version}')
|
|
35
|
-
|
|
36
|
-
`
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/vite-plugin-html.ts
|
|
44
|
-
import { loadEnv } from "vite";
|
|
45
|
-
function vitePluginHtml() {
|
|
46
|
-
let env = {};
|
|
47
|
-
return {
|
|
48
|
-
name: "vite-plugin-html",
|
|
49
|
-
enforce: "pre",
|
|
50
|
-
config(config, { mode }) {
|
|
51
|
-
env = loadEnv(mode, process.cwd());
|
|
52
|
-
},
|
|
53
|
-
transformIndexHtml(html) {
|
|
54
|
-
Object.keys(env).forEach((key) => {
|
|
55
|
-
const regex = new RegExp(`%${key}%`, "g");
|
|
56
|
-
html = html.replace(regex, env[key]);
|
|
57
|
-
});
|
|
58
|
-
return html;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export {
|
|
63
|
-
vitePluginHtml,
|
|
64
|
-
vitePluginLog
|
|
65
|
-
};
|