当前位置: 首页 > news >正文

做网站时怎样图片上传怎么才能让图片不变形_有什么插件吗西安seo网站管理

做网站时怎样图片上传怎么才能让图片不变形_有什么插件吗,西安seo网站管理,如何做统计信息的网站,营销型网站制作企业简介 StyleX 是由 Meta 开发的零运行时 CSS-in-JS 解决方案,在构建时将样式编译为静态 CSS,消除运行时开销。 核心特性 零运行时开销 – 构建时编译为静态 CSS类型安全 – 完整的 TypeScript 支持原子化 CSS – 自动生成原子化类名,最小化…

简介

StyleX 是由 Meta 开发的零运行时 CSS-in-JS 解决方案,在构建时将样式编译为静态 CSS,消除运行时开销。

核心特性

  • 零运行时开销 – 构建时编译为静态 CSS
  • 类型安全 – 完整的 TypeScript 支持
  • 原子化 CSS – 自动生成原子化类名,最小化包体积
  • 开发体验 – 热重载、错误提示、工具链集成

快速开始

安装

npm install @stylexjs/stylex
npm install -D @stylexjs/rollup-plugin

Vite 配置

// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import stylexPlugin from "@stylexjs/rollup-plugin";export default defineConfig({plugins: [stylexPlugin({dev: true,runtimeInjection: true,genConditionalClasses: true,fileName: "stylex.css",unstable_moduleResolution: {type: "commonJS",rootDir: process.cwd(),},}),react(),],
});

基础用法

创建样式

import * as stylex from "@stylexjs/stylex";// 简单的样式定义
const styles = stylex.create({button: {padding: 16,margin: 8,borderRadius: 4,borderWidth: 1,borderStyle: "solid",borderColor: "#ccc",backgroundColor: "#f0f0f0",cursor: "pointer",fontSize: 16,},primary: {backgroundColor: "#007bff",borderColor: "#007bff",color: "white",},
});function StyleXButton({ variant, children }) {const buttonProps = stylex.props(styles.button,variant === "primary" && styles.primary);return <button {...buttonProps}>{children}</button>;
}

响应式设计

import * as stylex from "@stylexjs/stylex";const responsiveStyles = stylex.create({container: {padding: 16,"@media (max-width: 768px)": {padding: 8,},"@media (min-width: 1024px)": {padding: 32,},},
});

主题系统

//tokens.stylex.js
import * as stylex from "@stylexjs/stylex";// 定义主题变量
export const tokens = stylex.defineVars({primaryColor: "#007bff",backgroundColor: "#ffffff",textColor: "#333333",spacing: "16px",
});// 暗色主题
export const darkTheme = stylex.createTheme(tokens, {primaryColor: "#0d6efd",backgroundColor: "#1a1a1a",textColor: "#ffffff",spacing: "16px",
});
import * as stylex from "@stylexjs/stylex";
import { tokens, darkTheme } from "./tokens.stylex.js";// 使用主题
const themedStyles = stylex.create({card: {backgroundColor: tokens.backgroundColor,color: tokens.textColor,padding: tokens.spacing,},
});function ThemedCard({ isDark, children }) {const themeProps = stylex.props(isDark && darkTheme);const cardProps = stylex.props(themedStyles.card);return (<div {...themeProps}><div {...cardProps}>{children}</div></div>);
}

实际应用示例

卡片组件

const cardStyles = stylex.create({card: {backgroundColor: "white",borderRadius: 8,boxShadow: "0 2px 8px rgba(0, 0, 0, 0.1)",overflow: "hidden",transition: "transform 0.2s ease",":hover": {transform: "translateY(-2px)",},},header: {padding: 16,borderBottom: "1px solid #e9ecef",},content: {padding: 16,},
});function Card({ title, children }) {const cardProps = stylex.props(cardStyles.card);const headerProps = stylex.props(cardStyles.header);const contentProps = stylex.props(cardStyles.content);return (<div {...cardProps}>{title && (<div {...headerProps}><h3>{title}</h3></div>)}<div {...contentProps}>{children}</div></div>);
}

表单组件

const formStyles = stylex.create({input: {width: "100%",padding: "8px 12px",border: "1px solid #ddd",borderRadius: 4,":focus": {outline: "none",borderColor: "#007bff",boxShadow: "0 0 0 2px rgba(0, 123, 255, 0.25)",},},error: {borderColor: "#dc3545",},button: {padding: "12px 24px",backgroundColor: "#007bff",color: "white",border: "none",borderRadius: 4,cursor: "pointer",":hover": {backgroundColor: "#0056b3",},},
});

工具集成

高级 Vite 配置

// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import stylexPlugin from "@stylexjs/rollup-plugin";export default defineConfig({plugins: [react(),stylexPlugin({dev: process.env.NODE_ENV === "development",genConditionalClasses: true,fileName: "stylex.css",minify: process.env.NODE_ENV === "production",// 自定义类名生成classNamePrefix: "sx",// 启用样式去重unstable_moduleResolution: {type: "commonJS",rootDir: process.cwd(),},}),],build: {// 确保 CSS 被正确提取cssCodeSplit: true,rollupOptions: {output: {assetFileNames: (assetInfo) => {if (assetInfo.name === "stylex.css") {return "assets/stylex.[hash].css";}return "assets/[name].[hash][extname]";},},},},
});

TypeScript 支持

// stylex.d.ts
declare module "@stylexjs/stylex" {export function create<T extends Record<string, any>>(styles: T): { [K in keyof T]: string };export function defineVars<T extends Record<string, string | number>>(vars: T): T;export function createTheme<T>(baseTheme: T, overrides: Partial<T>): string;export default function stylex(...styles: (string | false | null | undefined)[]): string;
}

最佳实践

样式组织

// tokens.js - 设计令牌
export const tokens = stylex.defineVars({colorPrimary: "#007bff",colorSecondary: "#6c757d",spacingS: "8px",spacingM: "16px",spacingL: "24px",fontSizeS: "12px",fontSizeM: "14px",borderRadius: "4px",
});// Button.stylex.js - 组件样式
import { tokens } from "./tokens";export const buttonStyles = stylex.create({base: {padding: `${tokens.spacingS} ${tokens.spacingM}`,fontSize: tokens.fontSizeM,borderRadius: tokens.borderRadius,border: "none",cursor: "pointer",},primary: {backgroundColor: tokens.colorPrimary,color: "white",},secondary: {backgroundColor: tokens.colorSecondary,color: "white",},
});

条件样式

const messageStyles = stylex.create({base: {padding: 16,borderRadius: 4,marginBottom: 16,},success: {backgroundColor: "#d4edda",color: "#155724",},error: {backgroundColor: "#f8d7da",color: "#721c24",},
});function Message({ type, children }) {const messageProps = stylex.props(messageStyles.base,type === "success" && messageStyles.success,type === "error" && messageStyles.error);return <div {...messageProps}>{children}</div>;
}

常见问题

Q: StyleX 与其他 CSS-in-JS 库有什么区别?
A: StyleX 的主要优势是零运行时开销,在构建时编译为静态 CSS。

Q: 如何处理动态样式?
A: 使用 CSS 变量或函数参数传递动态值。

Q: 是否支持 SSR?
A: 完全支持,由于样式在构建时生成,无客户端和服务端不一致问题。

总结

StyleX 是一个强大的零运行时 CSS-in-JS 解决方案,特别适合:

  • 大型 React 应用程序
  • 性能要求严格的项目
  • 需要类型安全的团队
  • 追求最佳构建产物的项目

主要优势:零运行时开销、类型安全、原子化 CSS、优秀的开发体验。通过构建时编译,StyleX 既保持了 CSS-in-JS 的开发体验,又获得了静态 CSS 的性能优势。

 StyleX:Meta推出的高性能零运行时CSS-in-JS解决方案 - 高质量源码分享平台-免费下载各类网站源码与模板及前沿技术分享

http://www.dtcms.com/a/418673.html

相关文章:

  • 网站域名备案注册证书查询编程软件哪个好用
  • Matlab通过GUI实现点云的ICP配准
  • Ubuntu 部署 ClickHouse:高性能分析型数据库(附shell脚本一键部署↓)
  • 【GUI自动化测试】菜单控件操作与记事本自动化测试实践
  • FFmpeg-vflip滤镜使用
  • 有没有做线播放网站合肥百度快照优化排名
  • 友链交换网站源码中信建设有限责任公司唐万哩
  • 具有品牌的上海网站建设山西运城网站开发
  • 网约车架构
  • K8s StorageClass配置实战:从入门到精通
  • 鼻毛修剪器MCU方案开发设计
  • 为什么LLM会使用到向量这种数学工具?
  • LocalStorage Token vs HttpOnly Cookie 认证方案
  • ArkUI V2中Repeat组件使用注意事项总结
  • 自动字幕翻译避坑指南
  • Go vs. PHP:核心优势劣势对比
  • Go 语言中的**数组 (Array)*用法
  • php 网站部署虚拟主机安装wordpress
  • 浙江省旅游企业网站建设情况做最最优秀的视频网站有哪些
  • 设计模式第五章(门面模式)
  • 海康相机SDK封装
  • 大模型应用:一个基于AI大模型的自动邮件简报系统 - Flask + HTML 方案
  • 开源 C# 快速开发(八)通讯--Tcp服务器端
  • MTK调试-电池识别
  • 网站目标网页制作下载图片代码
  • 钱站网站如何建设手机移动网站
  • Vue调用浏览器打印
  • 捷讯官网 网站建设网站到期只续域名不续空间能打开吗
  • CS231n学习笔记1-4: Image Features
  • DragonBalls_One009*