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.4 to 1.8.5

2

package.json
{
"name": "vite-plugin-style-to-vw",
"version": "1.8.4",
"version": "1.8.5",
"description": "一个可以将签内样式px转换vw的plugin",

@@ -5,0 +5,0 @@ "exports": {

@@ -186,4 +186,20 @@ # vite-plugin-style-to-vw

## If you want to use it manually, please use the following method
### need install vite-plugin-top-level-await
```
pnpm add vite-plugin-top-level-await -D
```
```javascript
import topLevelAwait from "vite-plugin-top-level-await";
defineConfig({
plugins: [topLevelAwait({
promiseExportName: '__tla',
promiseImportName: (i) => `__tla_${i}`
})]
})
```
```javascript
import { stylePxToVw } from "vite-plugin-style-to-vw";

@@ -190,0 +206,0 @@

@@ -194,4 +194,21 @@

## 如果您想手动使用,请使用以下方法
### 需要安装vite-plugin-top-level-await
```
pnpm add vite-plugin-top-level-await -D
```
```javascript
import topLevelAwait from "vite-plugin-top-level-await";
defineConfig({
plugins: [topLevelAwait({
promiseExportName: '__tla',
promiseImportName: (i) => `__tla_${i}`
})]
})
```
```javascript
import { stylePxToVw } from "vite-plugin-style-to-vw";

@@ -198,0 +215,0 @@

@@ -6,3 +6,3 @@ import type { IdefaultsProp } from './index.d'

const defaultsProp: IdefaultsProp = {
allReplace:false, // 是否全局替换
allReplace: false, // 是否全局替换
unitToConvert: "px", // 需要转换的单位,默认为"px"

@@ -14,3 +14,3 @@ viewportWidth: 750, // 设计稿的视口宽度,如传入函数,函数的参数为当前处理的文件路径

minPixelValue: 1, // 设置最小的转换数值,如果为 1 的话,只有大于 1 的值会被转换
attributeList:[]
attributeList: []
};

@@ -51,8 +51,8 @@

const dealAttributeList = (code,attributeList,customOptions)=>{
if(Array.isArray(attributeList) && attributeList.length){
const dealAttributeList = (code, attributeList, customOptions) => {
if (Array.isArray(attributeList) && attributeList.length) {
for (let index = 0; index < attributeList.length; index++) {
let copyCode = code
const element = attributeList[index];
const styleRegex = new RegExp(`${element}\s*(:|=)\s*(?:"([^"]*?)"|'([^']*?)'|{([^}]*)})`,'g')
const styleRegex = new RegExp(`${element}\s*(:|=)\s*(?:"([^"]*?)"|'([^']*?)'|{([^}]*)})`, 'g')

@@ -88,3 +88,3 @@ const styleMatches = code.match(styleRegex) as string[]

return code
}else {
} else {
return code

@@ -101,3 +101,3 @@ }

// 异步写入文件
fs.writeFileSync(process.cwd()+"/node_modules/vite-plugin-style-to-vw/dist/file.json", JSON.stringify(customOptions), 'utf8');
fs.writeFileSync(process.cwd() + "/node_modules/vite-plugin-style-to-vw/dist/file.json", JSON.stringify(customOptions), 'utf8');
// console.log('文件写入成功!');

@@ -107,3 +107,3 @@ } catch (error) {

}
const isAllReplace = customOptions.allReplace
const isAllReplace = customOptions.allReplace
const replaceReg = isAllReplace ? allReplace : styleRegex

@@ -156,6 +156,9 @@ return {

}
}
if (!isAllReplace) {
// 处理属性列表
code = dealAttributeList(code,customOptions.attributeList,customOptions)
code = dealAttributeList(code, customOptions.attributeList, customOptions)
}
} else if (/\.tsx|\.jsx$/.test(id)) {

@@ -194,4 +197,7 @@ let _source = code

}
}
// 处理属性列表
if (!isAllReplace) {
// 处理属性列表
code = dealAttributeList(code,customOptions.attributeList,customOptions)
code = dealAttributeList(code, customOptions.attributeList, customOptions)
}

@@ -198,0 +204,0 @@ // react 设置important

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