
Research
Shai-Hulud Descends to Hades: Miasma Worm Campaign Spreads with New PyPI Wave
Socket found 37 malicious PyPI wheels that abuse Python startup hooks to launch a Bun-powered credential stealer tied to Mini Shai-Hulud/Miasma.
@jiayouzuo/css-scope-vite
Advanced tools
Vite插件:通过hash前缀实现CSS作用域隔离,解决模块联邦中的样式冲突问题。
在模块联邦(微前端)架构中,主应用和远端应用可能使用不同版本的antd,导致样式冲突:
主应用(antd 5.x):.ant-btn { color: blue; }
远端应用(antd 4.x):.ant-btn { color: red; }
→ 样式互相覆盖!
使用本插件后:
主应用:.ha1b2c3d-ant-btn { color: blue; }
远端应用:.he5f6g7h-ant-btn { color: red; }
→ 完全隔离!
npm install @jiayouzuo/css-scope-vite -D
# 或
pnpm add @jiayouzuo/css-scope-vite -D
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import cssScopePlugin from '@jiayouzuo/css-scope-vite'
export default defineConfig({
plugins: [
// ⚠️ 重要:cssScopePlugin 必须放在 react() 之前!
cssScopePlugin({
scope: '[hash:8]', // hash长度,默认8位
projectId: 'my-app', // 项目标识,用于生成唯一hash
include: [
'src/', // 处理用户代码
'node_modules/antd/', // 处理antd的CSS和JS
'node_modules/@designable/' // 处理@designable的CSS和JS
],
exclude: [] // 排除的目录(可选)
}),
react()
]
})
Vite插件按数组顺序执行。本插件需要处理原始的JSX代码来识别和替换className:
// 原始JSX代码
<div className="header-box">
// cssScopePlugin处理后
<div className="ha1b2c3d-header-box">
// 最后由react()编译成
React.createElement("div", { className: "ha1b2c3d-header-box" })
如果react()先执行,JSX会被编译成React.createElement调用,本插件就无法识别className属性了。
| 选项 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| scope | string | 是 | - | hash格式,如 [hash:8] |
| projectId | string | 否 | package.json的name | 项目标识,用于生成唯一hash |
| include | string[] | 是 | - | 需要处理的目录列表 |
| exclude | string[] | 否 | [] | 排除的目录列表 |
重要:只有在 include 中配置的路径才会被处理,包括:
include: [
'src/', // 用户代码
'node_modules/antd/', // antd 的 CSS 和 JS
'node_modules/@designable/' // @designable 的 CSS 和 JS
]
如果只配置了 'src/',则 antd 和 @designable 的样式不会被处理。
defaultPrefixCls 变量Layout.defaultProps.prefixCls'h' + md5(projectId).slice(0, hashLength)/* 原CSS */
.ant-btn { color: blue; }
.dn-app { background: #fff; }
.header-box { padding: 10px; }
/* 转换后 */
.ha1b2c3d-ant-btn { color: blue; }
.ha1b2c3d-dn-app { background: #fff; }
.ha1b2c3d-header-box { padding: 10px; }
/* 原JSX */
<div className="header-box">
<Button className="my-btn">
/* 转换后 */
<div className="ha1b2c3d-header-box">
<Button className="ha1b2c3d-my-btn">
include 配置后需要清除 node_modules/.vite 缓存启动时控制台会输出:
[css-scope-plugin] 项目ID: my-app, Hash前缀: ha1b2c3d
MIT
FAQs
Vite插件:通过hash前缀实现CSS作用域隔离,解决模块联邦中的样式冲突
We found that @jiayouzuo/css-scope-vite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Socket found 37 malicious PyPI wheels that abuse Python startup hooks to launch a Bun-powered credential stealer tied to Mini Shai-Hulud/Miasma.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.