mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-11 13:02:49 +00:00
优化
This commit is contained in:
parent
c496af0566
commit
9cf476e603
24
packages/vite-plugin/dist/index.d.ts
vendored
24
packages/vite-plugin/dist/index.d.ts
vendored
@ -1,24 +1,2 @@
|
||||
import type { Config } from "../types";
|
||||
export declare function cool(options: Config.Options): (import("vite").Plugin<any> | Promise<import("vite").Plugin<any>> | {
|
||||
name: string;
|
||||
enforce: "pre";
|
||||
config(): {
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: {
|
||||
postcssPlugin: string;
|
||||
prepare(): {
|
||||
Rule(rule: any): void;
|
||||
Declaration(decl: any): void;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
};
|
||||
};
|
||||
transform(code: string, id: string): {
|
||||
code: string;
|
||||
map: {
|
||||
mappings: string;
|
||||
};
|
||||
} | null;
|
||||
}[])[];
|
||||
export declare function cool(options: Config.Options): (import("vite").Plugin<any> | Promise<import("vite").Plugin<any>> | import("vite").Plugin<any>[])[];
|
||||
|
||||
35
packages/vite-plugin/dist/index.js
vendored
35
packages/vite-plugin/dist/index.js
vendored
@ -44,6 +44,12 @@
|
||||
svg: {
|
||||
skipNames: ["base"],
|
||||
},
|
||||
tailwind: {
|
||||
enable: true,
|
||||
remUnit: 16,
|
||||
remPrecision: 6,
|
||||
rpxRatio: 2,
|
||||
},
|
||||
};
|
||||
|
||||
// 根目录
|
||||
@ -1052,6 +1058,9 @@ if (typeof window !== 'undefined') {
|
||||
"]": "-",
|
||||
"(": "-",
|
||||
")": "-",
|
||||
"{": "-",
|
||||
"}": "-",
|
||||
$: "-v-",
|
||||
"#": "-h-",
|
||||
"!": "-i-",
|
||||
"/": "-s-",
|
||||
@ -1231,12 +1240,12 @@ if (typeof window !== 'undefined') {
|
||||
* @param options 配置项
|
||||
* @returns PostCSS 插件对象
|
||||
*/
|
||||
function postcssRemToRpx(options) {
|
||||
function postcssRemToRpx() {
|
||||
return {
|
||||
postcssPlugin: "vite-cool-uniappx-remToRpx",
|
||||
prepare() {
|
||||
const handledSelectors = new Set();
|
||||
const { remUnit = 16, remPrecision = 6, rpxRatio = 2 } = options;
|
||||
const { remUnit = 16, remPrecision = 6, rpxRatio = 2 } = config.tailwind;
|
||||
const factor = remUnit * rpxRatio;
|
||||
return {
|
||||
Rule(rule) {
|
||||
@ -1307,16 +1316,8 @@ if (typeof window !== 'undefined') {
|
||||
/**
|
||||
* Vite 插件:自动转换 .uvue 文件中的 Tailwind 类名为安全字符
|
||||
* 并自动注入 rem 转 rpx 的 PostCSS 插件
|
||||
* @param options 配置项
|
||||
* @returns Vite 插件对象
|
||||
*/
|
||||
function tailwindTransformPlugin(options = {}) {
|
||||
const merged = {
|
||||
remUnit: 16,
|
||||
remPrecision: 6,
|
||||
rpxRatio: 2,
|
||||
...options,
|
||||
};
|
||||
function tailwindTransformPlugin() {
|
||||
return {
|
||||
name: "vite-cool-uniappx-tailwind",
|
||||
enforce: "pre",
|
||||
@ -1324,7 +1325,7 @@ if (typeof window !== 'undefined') {
|
||||
return {
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: [postcssRemToRpx(merged)],
|
||||
plugins: [postcssRemToRpx()],
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -1368,9 +1369,11 @@ if (typeof window !== 'undefined') {
|
||||
* @param options 配置项
|
||||
* @returns Vite 插件数组
|
||||
*/
|
||||
function uniappX(options) {
|
||||
function uniappX() {
|
||||
if (config.type == "uniapp-x") {
|
||||
return [tailwindTransformPlugin(options?.tailwind)];
|
||||
if (config.tailwind.enable) {
|
||||
return [tailwindTransformPlugin()];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@ -1404,6 +1407,10 @@ if (typeof window !== 'undefined') {
|
||||
lodash.merge(config.eps.mapping, mapping);
|
||||
}
|
||||
}
|
||||
// tailwind
|
||||
if (options.tailwind) {
|
||||
lodash.assign(config.tailwind, options.tailwind);
|
||||
}
|
||||
return [base(), virtual(), uniappX(), demo(options.demo)];
|
||||
}
|
||||
|
||||
|
||||
35
packages/vite-plugin/dist/uniapp-x/index.d.ts
vendored
35
packages/vite-plugin/dist/uniapp-x/index.d.ts
vendored
@ -1,38 +1,7 @@
|
||||
interface PostcssRemToRpxOptions {
|
||||
remUnit?: number;
|
||||
remPrecision?: number;
|
||||
rpxRatio?: number;
|
||||
}
|
||||
interface TailwindTransformOptions extends PostcssRemToRpxOptions {
|
||||
}
|
||||
import type { Plugin } from "vite";
|
||||
/**
|
||||
* uniappX 入口,自动注入 Tailwind 类名转换插件
|
||||
* @param options 配置项
|
||||
* @returns Vite 插件数组
|
||||
*/
|
||||
export declare function uniappX(options?: {
|
||||
tailwind?: TailwindTransformOptions;
|
||||
}): {
|
||||
name: string;
|
||||
enforce: "pre";
|
||||
config(): {
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: {
|
||||
postcssPlugin: string;
|
||||
prepare(): {
|
||||
Rule(rule: any): void;
|
||||
Declaration(decl: any): void;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
};
|
||||
};
|
||||
transform(code: string, id: string): {
|
||||
code: string;
|
||||
map: {
|
||||
mappings: string;
|
||||
};
|
||||
} | null;
|
||||
}[];
|
||||
export {};
|
||||
export declare function uniappX(): Plugin<any>[];
|
||||
|
||||
@ -41,4 +41,10 @@ export const config: Config.Data = {
|
||||
svg: {
|
||||
skipNames: ["base"],
|
||||
},
|
||||
tailwind: {
|
||||
enable: true,
|
||||
remUnit: 16,
|
||||
remPrecision: 6,
|
||||
rpxRatio: 2,
|
||||
},
|
||||
};
|
||||
|
||||
@ -45,5 +45,10 @@ export function cool(options: Config.Options) {
|
||||
}
|
||||
}
|
||||
|
||||
// tailwind
|
||||
if (options.tailwind) {
|
||||
assign(config.tailwind, options.tailwind);
|
||||
}
|
||||
|
||||
return [base(), virtual(), uniappX(), demo(options.demo)];
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// @ts-ignore
|
||||
import valueParser from "postcss-value-parser";
|
||||
import { config } from "../config";
|
||||
import type { Plugin } from "vite";
|
||||
import { Config } from "../../types";
|
||||
|
||||
/**
|
||||
* Tailwind CSS 特殊字符映射表
|
||||
@ -11,6 +13,9 @@ const TAILWIND_SAFE_CHAR_MAP: Record<string, string> = {
|
||||
"]": "-",
|
||||
"(": "-",
|
||||
")": "-",
|
||||
"{": "-",
|
||||
"}": "-",
|
||||
$: "-v-",
|
||||
"#": "-h-",
|
||||
"!": "-i-",
|
||||
"/": "-s-",
|
||||
@ -202,23 +207,17 @@ function rgbToRgba(value: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
interface PostcssRemToRpxOptions {
|
||||
remUnit?: number;
|
||||
remPrecision?: number;
|
||||
rpxRatio?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* PostCSS 插件:将 rem 单位转换为 rpx,并处理 Tailwind 特殊字符
|
||||
* @param options 配置项
|
||||
* @returns PostCSS 插件对象
|
||||
*/
|
||||
function postcssRemToRpx(options: PostcssRemToRpxOptions) {
|
||||
function postcssRemToRpx() {
|
||||
return {
|
||||
postcssPlugin: "vite-cool-uniappx-remToRpx",
|
||||
prepare() {
|
||||
const handledSelectors = new Set<string>();
|
||||
const { remUnit = 16, remPrecision = 6, rpxRatio = 2 } = options;
|
||||
const { remUnit = 16, remPrecision = 6, rpxRatio = 2 } = config.tailwind;
|
||||
const factor = remUnit * rpxRatio;
|
||||
|
||||
return {
|
||||
@ -289,37 +288,26 @@ function postcssRemToRpx(options: PostcssRemToRpxOptions) {
|
||||
}
|
||||
postcssRemToRpx.postcss = true;
|
||||
|
||||
interface TailwindTransformOptions extends PostcssRemToRpxOptions {}
|
||||
|
||||
/**
|
||||
* Vite 插件:自动转换 .uvue 文件中的 Tailwind 类名为安全字符
|
||||
* 并自动注入 rem 转 rpx 的 PostCSS 插件
|
||||
* @param options 配置项
|
||||
* @returns Vite 插件对象
|
||||
*/
|
||||
function tailwindTransformPlugin(options: TailwindTransformOptions = {}) {
|
||||
const merged: Required<TailwindTransformOptions> = {
|
||||
remUnit: 16,
|
||||
remPrecision: 6,
|
||||
rpxRatio: 2,
|
||||
...options,
|
||||
};
|
||||
|
||||
function tailwindTransformPlugin() {
|
||||
return {
|
||||
name: "vite-cool-uniappx-tailwind",
|
||||
enforce: "pre" as const,
|
||||
enforce: "pre",
|
||||
|
||||
config() {
|
||||
return {
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: [postcssRemToRpx(merged)],
|
||||
plugins: [postcssRemToRpx()],
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
transform(code: string, id: string) {
|
||||
transform(code, id) {
|
||||
if (!id.includes(".uvue")) return null;
|
||||
|
||||
let resultCode = code;
|
||||
@ -353,7 +341,7 @@ function tailwindTransformPlugin(options: TailwindTransformOptions = {}) {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
} as Plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -361,9 +349,11 @@ function tailwindTransformPlugin(options: TailwindTransformOptions = {}) {
|
||||
* @param options 配置项
|
||||
* @returns Vite 插件数组
|
||||
*/
|
||||
export function uniappX(options?: { tailwind?: TailwindTransformOptions }) {
|
||||
export function uniappX() {
|
||||
if (config.type == "uniapp-x") {
|
||||
return [tailwindTransformPlugin(options?.tailwind)];
|
||||
if (config.tailwind.enable) {
|
||||
return [tailwindTransformPlugin()];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
11
packages/vite-plugin/types/index.d.ts
vendored
11
packages/vite-plugin/types/index.d.ts
vendored
@ -106,6 +106,17 @@ export declare namespace Config {
|
||||
// 跳过拼接模块名
|
||||
skipNames?: string[];
|
||||
};
|
||||
// tailwind
|
||||
tailwind?: {
|
||||
// 是否开启tailwind
|
||||
enable?: boolean;
|
||||
// 根元素字体大小
|
||||
remUnit?: number;
|
||||
// 小数位数
|
||||
remPrecision?: number;
|
||||
// 转换比例
|
||||
rpxRatio?: number;
|
||||
};
|
||||
}
|
||||
interface Data {
|
||||
type: Type;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user