vite-plugin-style-to-vw
Advanced tools
Comparing version 1.8.9 to 1.8.10
{ | ||
"name": "vite-plugin-style-to-vw", | ||
"version": "1.8.9", | ||
"version": "1.8.10", | ||
"description": "一个可以将签内样式px转换vw的plugin", | ||
@@ -10,13 +10,7 @@ "exports": { | ||
"require": "./dist/index.js" | ||
}, | ||
"./util": { | ||
"types": "./dist/util.d.ts", | ||
"import":"./dist/util.mjs" | ||
} | ||
} | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "npm run build:index && npm run build:util", | ||
"build:index":"tsup src/index.ts --dts --format esm --minify --outDir dist", | ||
"build:util":"tsup src/util.ts --dts --format esm --minify --outDir dist", | ||
"build": "tsup src/index.ts --dts --format esm --minify --outDir dist", | ||
"test:vue": "cd examples/my-vue-app && pnpm i && pnpm run dev", | ||
@@ -59,3 +53,2 @@ "test:react": "cd examples/my-react-app && pnpm i && pnpm run dev" | ||
"devDependencies": { | ||
"@rollup/pluginutils": "^5.1.0", | ||
"@types/node": "^18.14.0", | ||
@@ -76,4 +69,5 @@ "@typescript-eslint/eslint-plugin": "^5.53.0", | ||
"dependencies": { | ||
"pluginutils": "link:@types/@rollup/pluginutils" | ||
"pluginutils": "link:@types/@rollup/pluginutils", | ||
"rollup-pluginutils": "^2.8.2" | ||
} | ||
} |
110
src/index.ts
import type { IdefaultsProp } from './index.d' | ||
import fs from 'fs' | ||
import utils from '@rollup/pluginutils' | ||
// let utils | ||
// // @ts-ignore | ||
// if (typeof window === "undefined") { | ||
// utils = await import('@rollup/pluginutils') | ||
// utils = utils.default | ||
// console.log('utils',utils) | ||
// } | ||
// import util from '@rollup/pluginutils' | ||
let utils | ||
// @ts-ignore | ||
if (typeof window === "undefined") { | ||
utils = await import('rollup-pluginutils') | ||
} | ||
@@ -52,5 +50,3 @@ // 默认参数 | ||
} | ||
// let extraOptions = defaultsProp | ||
let extraOptions = defaultsProp | ||
const templateReg = /<template>([\s\S]+)<\/template>/gi; | ||
@@ -262,50 +258,50 @@ const pxGlobalReg = /(\d+)px/g; | ||
// @ts-ignore | ||
// if (typeof window !== "undefined") { | ||
// try { | ||
// // 读取文件,node端生成合并的配置, | ||
// // ts忽略下文 | ||
// // @ts-ignore | ||
// const json = await import('/node_modules/vite-plugin-style-to-vw/dist/file.json') | ||
// extraOptions = json.default | ||
// } catch (error) { | ||
// } | ||
// } | ||
if (typeof window !== "undefined") { | ||
try { | ||
// 读取文件,node端生成合并的配置, | ||
// ts忽略下文 | ||
// @ts-ignore | ||
const json = await import('/node_modules/vite-plugin-style-to-vw/dist/file.json') | ||
extraOptions = json.default | ||
} catch (error) { | ||
} | ||
} | ||
// // 手动转换成vw 100 ==> 13.33333 '100px' ==> '13.33333px | ||
// export const stylePxToVw = (code: string | number, customOptions: IdefaultsProp = {}) => { | ||
// const copyExtraOptions = Object.assign({}, extraOptions) | ||
// customOptions = Object.assign(copyExtraOptions, customOptions) | ||
// if (typeof code === 'number' || (typeof Number(code) === 'number' && !isNaN(Number(code | ||
// )))) { | ||
// const returnCode = code.toString().replace(/(\d+)/g, (match) => { | ||
// return match.replace( | ||
// /(\d+)/g, | ||
// createPxReplace( | ||
// customOptions.viewportWidth as number, | ||
// customOptions.minPixelValue as number, | ||
// customOptions.unitPrecision as number, | ||
// '' | ||
// ), | ||
// ) | ||
// 手动转换成vw 100 ==> 13.33333 '100px' ==> '13.33333px | ||
export const stylePxToVw = (code: string | number, customOptions: IdefaultsProp = {}) => { | ||
const copyExtraOptions = Object.assign({}, extraOptions) | ||
customOptions = Object.assign(copyExtraOptions, customOptions) | ||
if (typeof code === 'number' || (typeof Number(code) === 'number' && !isNaN(Number(code | ||
)))) { | ||
const returnCode = code.toString().replace(/(\d+)/g, (match) => { | ||
return match.replace( | ||
/(\d+)/g, | ||
createPxReplace( | ||
customOptions.viewportWidth as number, | ||
customOptions.minPixelValue as number, | ||
customOptions.unitPrecision as number, | ||
'' | ||
), | ||
) | ||
// }) | ||
// if (typeof code === 'number') { | ||
// return Number(returnCode) | ||
// } else { | ||
// return returnCode | ||
// } | ||
// } else { | ||
// return code.toString().replace(pxGlobalReg, (match) => { | ||
// return match.replace( | ||
// pxGlobalReg, | ||
// createPxReplace( | ||
// customOptions.viewportWidth as number, | ||
// customOptions.minPixelValue as number, | ||
// customOptions.unitPrecision as number, | ||
// customOptions.viewportUnit as string, | ||
// ), | ||
// ) | ||
// }) | ||
// } | ||
// } | ||
}) | ||
if (typeof code === 'number') { | ||
return Number(returnCode) | ||
} else { | ||
return returnCode | ||
} | ||
} else { | ||
return code.toString().replace(pxGlobalReg, (match) => { | ||
return match.replace( | ||
pxGlobalReg, | ||
createPxReplace( | ||
customOptions.viewportWidth as number, | ||
customOptions.minPixelValue as number, | ||
customOptions.unitPrecision as number, | ||
customOptions.viewportUnit as string, | ||
), | ||
) | ||
}) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
7
1
30545
2
10
342
+ Addedrollup-pluginutils@^2.8.2
+ Addedestree-walker@0.6.1(transitive)
+ Addedrollup-pluginutils@2.8.2(transitive)