Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-style-to-vw

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-style-to-vw - npm Package Compare versions

Comparing version 1.8.9 to 1.8.10

16

package.json
{
"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"
}
}
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc