Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
vite-plugin-style-to-vw
Advanced tools
A plugin that can convert intra-tag style px to vw
A plugin that can convert intra-tag style px to vw / rem
npm install vite-plugin-style-to-vw -D
or
pnpm install vite-plugin-style-to-vw -D
or
yarn add vite-plugin-style-to-vw -D
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vitePluginStyleToVw from "vite-plugin-style-to-vw";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vitePluginStyleToVw({
allReplace:false,
unitToConvert: "px",
viewportWidth: 750,
unitPrecision: 5,
viewportUnit: "vw",
fontViewportUnit: "vw",
minPixelValue: 1,
attributeList:[]
}), vue()],
});
Some plug-ins will convert class='text-20px' in the atomic plug-in class to class='text-2.666666666665vw', so I wrote this plug-in, only convert class =' text-20px 'in style
Since some plug-ins do not need to be atomized and want px in all attributes to be converted to vw, you can set the allReplace configuration option to true
vitePluginStyleToVw({
allReplace:false,
attributeList:['size','height','width'] // Additional properties that can be handled
})
vitePluginStyleToVw({
allReplace:true,
})
<h3 style="font-size: 28px;margin-top: 10px;width:500px">Test</h3>
<h3 style="
font-size: 28px;
margin-top: 10px;
width:500px;">
Test</h3>
<h3
:style="{fontSize:'28px',marginTop: '10px'}">
Test</h3>
<h3
style={{font-size:'28px';margin-top: '10px'}}>
Test</h3>
<h3
style=
{{font-size:'28px';
margin-top: '10px'}}
>
Test</h3>
<h3 style="font-size: 3.73333ww;margin-top: 1.33333vw;width:66.6667vw">Test</h3>
<h3 style="
font-size: 3.73333ww;
margin-top: 1.33333vw;
width:66.6667vw">
Test</h3>
<h3
style="font-size: 3.73333ww;margin-top: 1.33333vw;">
Test</h3>
<h3
style="font-size: 3.73333ww;margin-top: 1.33333vw;">
Test</h3>
<h3
style="font-size: 3.73333ww;margin-top: 1.33333vw;"
>
Test</h3>
import React from 'react'
import './App.css'
function App() {
return (
<>
<div
style={{
height: '100px',
width: '100px',
backgroundColor: 'blue',
paddingBottom: '30px',
}}
ref={(el) => {
if (el) {
el.style.setProperty('height', '100px', 'important');
el.style.setProperty('width', '100px', 'important');
el.style.setProperty('background-color', 'red');
el.style.setProperty('padding-bottom', '30px', 'important');
}
}}>A</div>
</>
)
}
export default App
pnpm add vite-plugin-top-level-await -D
import topLevelAwait from "vite-plugin-top-level-await";
defineConfig({
plugins: [topLevelAwait({
promiseExportName: '__tla',
promiseImportName: (i) => `__tla_${i}`
})]
})
import { stylePxToVw } from "vite-plugin-style-to-vw";
const a = stylePxToVw(100)
console.log(a) // 13.3333
const b = stylePxToVw('100')
console.log(b) // 13.3333
const c = stylePxToVw('100px')
console.log(c) // 13.3333vw
const d = stylePxToVw('100px', {
unitToConvert: "px", // The unit to be converted is "px" by default.
viewportWidth: 750, // The viewport width of the design draft, such as
unitPrecision: 0, // Precision retained after unit conversion.
viewportUnit: "vw", // Viewport units you want to use.
fontViewportUnit: "vw", // Viewport units used by fonts.
})
console.log(d) // 13vw
Default configuration
{
allReplace :false, // Replace all label attributes
unitToConvert: "px", // The unit to be converted is "px" by default.
viewportWidth: 750, // The viewport width of the design draft, such as the incoming function, whose parameter is the file path currently processed.
unitPrecision: 5, // Precision retained after unit conversion.
viewportUnit: "vw", // Viewport units you want to use.
fontViewportUnit: "vw", // Viewport units used by fonts.
minPixelValue: 1, // Set the minimum conversion value. If it is 1, only values greater than 1 will be converted.
attributeList:[] , // allReplace is false, ['width','size','height']
include:[], // Contains files under certain folders or specific files, such as files under 'node_modules'
exclude: [], // Ignore files under certain folders or specific files, such as files under 'node_modules'
}
FAQs
一个可以将签内样式px转换vw的plugin
The npm package vite-plugin-style-to-vw receives a total of 1 weekly downloads. As such, vite-plugin-style-to-vw popularity was classified as not popular.
We found that vite-plugin-style-to-vw demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.