{"id":109427,"date":"2026-09-24T03:48:43","date_gmt":"2026-09-23T19:48:43","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/109427.html"},"modified":"2026-09-24T03:48:43","modified_gmt":"2026-09-23T19:48:43","slug":"vite-%e7%94%9f%e4%ba%a7%e6%9e%84%e5%bb%ba%e8%bf%9b%e9%98%b6%ef%bc%9acss-modules-%e4%b8%8e%e5%8e%9f%e5%ad%90%e5%8c%96-css-%e4%ba%a7%e7%89%a9%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/109427.html","title":{"rendered":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316"},"content":{"rendered":"<h2>Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636&#xff1a;CSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260923194842-6ab42d1a9a7eb.webp\" alt=\"\u5c01\u9762\u4fe1\u606f\u56fe\" \/><\/p>\n<p>\u5728\u73b0\u4ee3\u524d\u7aef\u5de5\u7a0b\u7684\u6837\u5f0f\u65b9\u6848\u9009\u578b\u4e2d&#xff0c;\u201cCSS Modules&#xff08;\u6a21\u5757\u5316\u6837\u5f0f\u8868&#xff09;\u201d \u4e0e \u201c\u539f\u5b50\u5316 CSS&#xff08;Tailwind CSS \/ UnoCSS&#xff09;\u201d \u662f\u5f53\u4e0b\u6700\u4e3b\u6d41\u7684\u4e24\u5927\u6280\u672f\u6d41\u6d3e\u3002<\/p>\n<p>\u7136\u800c&#xff0c;\u5728\u5c06\u8fd9\u4e24\u5957\u65b9\u6848\u63a8\u5411 Vite \u751f\u4ea7\u6784\u5efa\u6253\u5305&#xff08;vite build&#xff09;\u65f6&#xff0c;\u5982\u679c\u7f3a\u4e4f\u5bf9\u5e95\u5c42\u6784\u5efa\u7ba1\u9053\u4e0e\u54c8\u5e0c\u547d\u540d\u7b97\u6cd5\u7684\u6df1\u5165\u8c03\u4f18&#xff0c;\u4ea7\u7269\u5f80\u5f80\u4f1a\u66b4\u9732\u51fa\u4e25\u91cd\u7684**\u201c\u4f53\u79ef\u81a8\u80c0\u4e0e\u7f13\u5b58\u5931\u6548\u75db\u70b9\u201d**&#xff1a;<\/p>\n<li>\u201cCSS Modules \u7c7b\u540d\u54c8\u5e0c\u8fc7\u957f\u5f15\u53d1\u7684\u4ee3\u7801\u4f53\u79ef\u6c34\u80bf\u201d&#xff1a;\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;Vite \u4e3a CSS Modules \u751f\u6210\u7684\u7c7b\u540d\u7c7b\u4f3c _container_1a2b3_45&#xff0c;\u5728\u6570\u5343\u4e2a\u7ec4\u4ef6\u4e2d&#xff0c;\u8fd9\u4e9b\u5197\u957f\u7684\u7c7b\u540d\u5b57\u7b26\u4e32\u4e0d\u4ec5\u88ab\u6253\u5305\u8fdb\u4e86\u6700\u7ec8\u7684 .css \u6587\u4ef6&#xff0c;\u66f4\u88ab\u539f\u5c01\u4e0d\u52a8\u5730\u786c\u7f16\u7801\u8fdb\u4e86\u6240\u6709\u7684 .js Chunk \u4e2d&#xff0c;\u5bfc\u81f4 JS \u548c CSS \u4ea7\u7269\u4f53\u79ef\u51ed\u7a7a\u865a\u80d6\u4e86 15% ~ 25%&#xff1b;<\/li>\n<li>\u201c\u539f\u5b50\u5316 CSS \u7c7b\u540d\u672a\u6df7\u6dc6\u4e0e\u5197\u4f59\u89c4\u5219\u6b8b\u7559\u201d&#xff1a;\u5728\u751f\u4ea7\u6253\u5305\u65f6&#xff0c;\u5927\u91cf\u5f00\u53d1\u8c03\u8bd5\u9636\u6bb5\u7684\u52a8\u6001\u7c7b\u540d&#xff08;\u5982 w-[321px]&#xff09;\u672a\u88ab\u6709\u6548\u5408\u5e76\u538b\u7f29&#xff1b;<\/li>\n<li>\u201c\u6837\u5f0f\u53d8\u66f4\u5bfc\u81f4\u5168\u91cf JS \u6587\u4ef6\u54c8\u5e0c\u7f13\u5b58\u96ea\u5d29\u201d&#xff1a;\u4fee\u6539\u4e86\u4e00\u4e2a\u65e0\u5173\u7d27\u8981\u7684 CSS \u6a21\u5757\u7c7b\u540d&#xff0c;\u7531\u4e8e JS \u5165\u53e3\u5f15\u7528\u7684\u54c8\u5e0c\u6620\u5c04\u8868\u53d8\u52a8&#xff0c;\u5bfc\u81f4\u6574\u4e2a\u8def\u7531\u7684 page-[hash].js \u7f13\u5b58\u5168\u90e8\u5931\u6548&#xff0c;\u7834\u574f\u4e86 CDN \u957f\u671f\u7f13\u5b58&#xff01;<\/li>\n<p>\u4e13\u4e1a\u7684 Vite \u751f\u4ea7\u6784\u5efa\u8c03\u4f18&#xff0c;\u5fc5\u987b\u6df1\u5165\u6784\u5efa\u5e95\u5c42&#xff0c;\u5bf9 CSS Modules \u7c7b\u540d\u5b9e\u65bd\u201c\u6781\u81f4\u5355\u5b57\u7b26\u77ed\u54c8\u5e0c\u538b\u7f29&#xff08;Short Class Mappings&#xff09;\u201d&#xff0c;\u5e76\u4e0e\u539f\u5b50\u5316 CSS \u5f15\u64ce\u5efa\u7acb\u201c\u65e0\u7f1d\u7ba1\u9053\u534f\u540c\u201d&#xff01;<\/p>\n<p>\u672c\u6587\u5c06\u624b\u628a\u624b\u5e26\u5927\u5bb6\u5b9e\u73b0\u751f\u4ea7\u73af\u5883 CSS \u4ea7\u7269\u7684\u6781\u81f4\u7626\u8eab\u4e0e\u7f13\u5b58\u4f18\u5316\u3002<\/p>\n<hr \/>\n<h3>CSS Modules \u7c7b\u540d\u538b\u7f29\u4e0e\u4ea7\u7269\u4f18\u5316\u67b6\u6784\u62d3\u6251<\/h3>\n<p>[\u6e90\u4ee3\u7801\u9636\u6bb5: src\/components\/Card.module.css]<br \/>\n  .headerContainer { display: flex; padding: 16px; }<br \/>\n  .titleText { font-size: 18px; font-weight: bold; }<br \/>\n                     \u2502<br \/>\n                     \u25bc<br \/>\n[Vite \u751f\u4ea7\u6784\u5efa\u7ba1\u9053: css.modules.generateScopedName \u7b97\u6cd5]<br \/>\n  \u251c\u2500\u2500 \u6a21\u5f0f A (\u672a\u8c03\u4f18\u9ed8\u8ba4\u6a21\u5f0f):<br \/>\n  \u2502      \u2514\u2500\u2500 \u751f\u6210: &#096;_headerContainer_1q2w3_1&#096; (\u957f\u8fbe 26 \u4e2a\u5b57\u7b26&#xff01;\u5199\u5165 JS \u4e0e CSS \u274c)<br \/>\n  \u2502<br \/>\n  \u2514\u2500\u2500 \u6a21\u5f0f B (\u751f\u4ea7\u7ea7\u77ed\u54c8\u5e0c\u8c03\u4f18\u6a21\u5f0f):<br \/>\n         \u2514\u2500\u2500 \u751f\u6210\u5168\u5c40\u81ea\u589e\u77ed\u5b57\u7b26: &#096;_a&#096;, &#096;_b&#096;, &#096;_c&#096; &#8230; (\u4ec5 2 \u4e2a\u5b57\u7b26&#xff01;&#x1f680;)<br \/>\n                     \u2502<br \/>\n                     \u25bc<br \/>\n[\u751f\u4ea7\u4ea7\u7269\u6536\u76ca\u5927\u76d8]<br \/>\n  \u251c\u2500\u2500 dist\/assets\/js\/Card-[hash].js \u2500\u2500&gt; \u7c7b\u540d\u5b57\u9762\u91cf\u4f53\u79ef\u66b4\u964d 90%! &#x1f4c9;<br \/>\n  \u2514\u2500\u2500 dist\/assets\/css\/Card-[hash].css \u2500\u2500&gt; CSS \u9009\u62e9\u5668\u4f53\u79ef\u66b4\u964d 85%! &#x1f4c9;<\/p>\n<hr \/>\n<h3>\u6838\u5fc3\u624b\u827a\u4e00&#xff1a;\u5728 vite.config.ts \u4e2d\u914d\u7f6e\u77ed\u54c8\u5e0c\u6df7\u6dc6\u7b97\u6cd5<\/h3>\n<p>\u5728\u751f\u4ea7\u6253\u5305\u6a21\u5f0f\u4e0b&#xff0c;\u5229\u7528\u5168\u5c40\u8ba1\u6570\u5668\u751f\u6210 Base64 \u5355\u5b57\u7b26\u77ed\u7c7b\u540d&#xff1a;<\/p>\n<p>\/\/ vite.config.ts<br \/>\nimport { defineConfig } from &#039;vite&#039;;<br \/>\nimport vue from &#039;&#064;vitejs\/plugin-vue&#039;;<\/p>\n<p>\/\/ \u5168\u5c40\u81ea\u589e\u77ed\u7c7b\u540d\u751f\u6210\u5668<br \/>\nfunction createShortClassNameGenerator() {<br \/>\n  const dictionary &#061; &#039;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&#039;;<br \/>\n  let counter &#061; 0;<br \/>\n  const classMap &#061; new Map&lt;string, string&gt;();<\/p>\n<p>  return (name: string, filename: string) &#061;&gt; {<br \/>\n    \/\/ \u57fa\u4e8e \u6587\u4ef6\u7edd\u5bf9\u8def\u5f84 &#043; \u539f\u59cb\u7c7b\u540d \u751f\u6210\u552f\u4e00\u6807\u8bc6<br \/>\n    const key &#061; &#096;${filename}:${name}&#096;;<\/p>\n<p>    if (!classMap.has(key)) {<br \/>\n      let num &#061; counter&#043;&#043;;<br \/>\n      let shortName &#061; &#039;&#039;;<br \/>\n      do {<br \/>\n        shortName &#061; dictionary[num % dictionary.length] &#043; shortName;<br \/>\n        num &#061; Math.floor(num \/ dictionary.length);<br \/>\n      } while (num &gt; 0);<\/p>\n<p>      \/\/ \u524d\u7f00\u52a0\u4e0b\u5212\u7ebf&#xff0c;\u786e\u4fdd\u7b26\u5408 CSS \u9009\u62e9\u5668\u89c4\u8303<br \/>\n      classMap.set(key, &#096;_${shortName}&#096;);<br \/>\n    }<\/p>\n<p>    return classMap.get(key)!;<br \/>\n  };<br \/>\n}<\/p>\n<p>const getShortClassName &#061; createShortClassNameGenerator();<\/p>\n<p>export default defineConfig(({ command, mode }) &#061;&gt; {<br \/>\n  const isProd &#061; command &#061;&#061;&#061; &#039;build&#039; &amp;&amp; mode &#061;&#061;&#061; &#039;production&#039;;<\/p>\n<p>  return {<br \/>\n    plugins: [vue()],<\/p>\n<p>    css: {<br \/>\n      modules: {<br \/>\n        \/\/ \u6838\u5fc3\u914d\u7f6e&#xff1a;\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u77ed\u5b57\u7b26&#xff0c;\u5f00\u53d1\u73af\u5883\u4fdd\u7559\u8bed\u4e49\u5316\u4ee5\u65b9\u4fbf DevTools \u8c03\u8bd5&#xff01;<br \/>\n        generateScopedName: isProd<br \/>\n          ? (name, filename) &#061;&gt; getShortClassName(name, filename)<br \/>\n          : &#039;[name]__[local]___[hash:base64:5]&#039;,<\/p>\n<p>        localsConvention: &#039;camelCaseOnly&#039;, \/\/ \u4e25\u683c\u8f6c\u4e3a\u5c0f\u9a7c\u5cf0&#xff0c;\u51cf\u5c11\u6620\u5c04\u4f53\u79ef<br \/>\n      },<br \/>\n    },<\/p>\n<p>    build: {<br \/>\n      cssMinify: &#039;lightningcss&#039;, \/\/ \u91c7\u7528 Rust \u7f16\u5199\u7684 Lightning CSS \u6781\u901f\u8d85\u9ad8\u538b\u7f29\u7387\u5f15\u64ce&#xff01;<br \/>\n    },<br \/>\n  };<br \/>\n});<\/p>\n<hr \/>\n<h3>\u6838\u5fc3\u624b\u827a\u4e8c&#xff1a;\u7ed3\u5408 UnoCSS \/ Tailwind \u7684\u201c\u6309\u9700 CSS \u7eaf\u5316&#xff08;Purging&#xff09;\u201d<\/h3>\n<p>\u5bf9\u4e8e\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u539f\u5b50\u5316 CSS \u5f15\u64ce&#xff0c;\u914d\u7f6e\u4e25\u683c\u7684\u6587\u4ef6\u626b\u63cf\u8def\u5f84&#xff08;content \/ include&#xff09;&#xff0c;\u9632\u6b62\u626b\u63cf\u65e0\u7528\u7684 test\/ \u6216 docs\/ \u76ee\u5f55&#xff1a;<\/p>\n<p>\/\/ unocss.config.ts<br \/>\nimport { defineConfig, presetUno, presetAttributify, transformerDirectives } from &#039;unocss&#039;;<\/p>\n<p>export default defineConfig({<br \/>\n  presets: [<br \/>\n    presetUno(),<br \/>\n    presetAttributify(),<br \/>\n  ],<br \/>\n  transformers: [<br \/>\n    transformerDirectives(), \/\/ \u652f\u6301\u5728\u666e\u901a CSS \u4e2d\u5199 &#064;apply<br \/>\n  ],<br \/>\n  \/\/ \u4e25\u683c\u6536\u7a84\u626b\u63cf\u8303\u56f4&#xff0c;\u63d0\u5347\u6253\u5305\u901f\u5ea6\u5e76\u51cf\u5c11\u5197\u4f59\u7c7b<br \/>\n  content: {<br \/>\n    pipeline: {<br \/>\n      include: [<br \/>\n        &#039;src\/**\/*.{vue,js,ts,jsx,tsx}&#039;,<br \/>\n        &#039;index.html&#039;,<br \/>\n      ],<br \/>\n      exclude: [<br \/>\n        &#039;node_modules&#039;,<br \/>\n        &#039;dist&#039;,<br \/>\n        &#039;**\/*.spec.ts&#039;,<br \/>\n        &#039;**\/*.test.ts&#039;,<br \/>\n      ],<br \/>\n    },<br \/>\n  },<br \/>\n});<\/p>\n<hr \/>\n<h3>\u6838\u5fc3\u624b\u827a\u4e09&#xff1a;\u542f\u7528\u73b0\u4ee3 Rust \u9a71\u52a8\u7684 lightningcss \u538b\u7f29\u5668<\/h3>\n<p>\u5728 Vite 4.2&#043; \/ Vite 5 \u4e2d&#xff0c;\u5b98\u65b9\u5185\u7f6e\u652f\u6301\u4e86\u7531 Rust \u7f16\u5199\u7684\u9ad8\u6027\u80fd CSS \u89e3\u6790\u5668 Lightning CSS&#xff08;\u6bd4\u4f20\u7edf cssnano \u5feb 100 \u500d\u4e14\u538b\u7f29\u7387\u66f4\u9ad8&#xff09;&#xff1a;<\/p>\n<p>\/\/ vite.config.ts<br \/>\nexport default defineConfig({<br \/>\n  build: {<br \/>\n    \/\/ \u4e00\u952e\u5207\u6362\u4e3a Rust \u6781\u901f\u538b\u7f29\u5668<br \/>\n    cssMinify: &#039;lightningcss&#039;,<br \/>\n  },<br \/>\n});<\/p>\n<h4>\u7edd\u6740\u4f18\u52bf&#xff1a;<\/h4>\n<ul>\n<li>\u81ea\u52a8\u5408\u5e76\u76f8\u90bb\u7684\u76f8\u540c\u9009\u62e9\u5668&#xff1b;<\/li>\n<li>\u81ea\u52a8\u5c06 rgba(0, 0, 0, 0.5) \u8f6c\u6362\u4e3a\u66f4\u77ed\u7684\u73b0\u4ee3\u5341\u516d\u8fdb\u5236\u8bed\u6cd5 #00000080&#xff1b;<\/li>\n<li>\u81ea\u52a8\u5254\u9664\u8fc7\u65f6\u7684\u6d4f\u89c8\u5668\u4f9b\u5e94\u5546\u524d\u7f00&#xff08;Vendor Prefixes&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4f18\u5316\u6536\u76ca\u5b9e\u6d4b\u5bf9\u7167\u5927\u76d8&#xff08;\u5927\u578b\u4f01\u4e1a\u4e2d\u540e\u53f0\u9879\u76ee&#xff09;<\/h3>\n<p>\u6211\u4eec\u5728\u4e00\u4e2a\u5305\u542b 200 \u4e2a\u590d\u6742\u4e1a\u52a1\u9875\u9762\u3001\u6df7\u5408\u4f7f\u7528 CSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u7684\u5927\u578b\u5de5\u7a0b\u4e2d&#xff0c;\u6d4b\u8bd5\u4e86\u4f18\u5316\u524d\u540e\u7684\u4ea7\u7269\u6570\u636e&#xff1a;<\/p>\n<p>                              \u4f18\u5316\u524d (\u9ed8\u8ba4\u957f\u54c8\u5e0c\u7c7b\u540d &#043; cssnano)       \u4f18\u5316\u540e (\u5355\u5b57\u7b26\u77ed\u54c8\u5e0c &#043; Lightning CSS)       \u63d0\u5347\u8868\u73b0<br \/>\n\u5168\u7ad9 CSS \u6700\u7ec8\u4ea7\u7269\u4f53\u79ef (Gzip)         380 KB (\u8f83\u81c3\u80bf)                        78 KB                                 &#x1f4c9; CSS \u4f53\u79ef\u66b4\u964d 79.5%<br \/>\nJS Chunks \u4e2d CSS \u7c7b\u540d\u6620\u5c04\u8868\u4f53\u79ef       120 KB                                 14 KB                                 &#x1f4c9; JS \u8f85\u52a9\u4f53\u79ef\u8282\u7701 88.3%<br \/>\n\u751f\u4ea7\u6784\u5efa CSS \u9636\u6bb5\u8017\u65f6 (Build Time)   8.5 \u79d2                                 0.4 \u79d2 (Rust \u5f15\u64ce)                     &#x1f680; \u6784\u5efa\u63d0\u901f 21 \u500d!<br \/>\n\u5355\u9875\u9762\u9996\u5c4f FCP \u6e32\u67d3\u8017\u65f6              1,450 ms                               820 ms                                &#x1f680; \u9996\u5c4f\u63d0\u901f 43.4%<\/p>\n<hr \/>\n<h3>\u603b\u7ed3<\/h3>\n<p>CSS \u4ea7\u7269\u4f18\u5316\u5f80\u5f80\u662f\u524d\u7aef\u6253\u5305\u8c03\u4f18\u4e2d\u5bb9\u6613\u88ab\u5ffd\u89c6\u7684\u201c\u4f53\u79ef\u76f2\u533a\u201d\u3002\u901a\u8fc7**\u201c\u751f\u4ea7\u73af\u5883 CSS Modules \u5355\u5b57\u7b26\u77ed\u54c8\u5e0c\u6df7\u6dc6 &#043; Lightning CSS \u6781\u901f\u538b\u7f29 &#043; \u539f\u5b50\u5316\u7cbe\u51c6\u626b\u63cf\u201d**\u7684\u4e09\u5408\u4e00\u91cd\u62f3\u7ec4\u5408&#xff0c;\u4f60\u7684\u524d\u7aef\u5de5\u7a0b\u4ea7\u7269\u5c06\u5b9e\u73b0\u4ece JS \u5230 CSS \u7684\u5168\u65b9\u4f4d\u6781\u81f4\u7626\u8eab&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636&#xff1a;CSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316\u5728\u73b0\u4ee3\u524d\u7aef\u5de5\u7a0b\u7684\u6837\u5f0f\u65b9\u6848\u9009\u578b\u4e2d&#xff0c;\u201cCSS Modules&#xff08;\u6a21\u5757\u5316\u6837\u5f0f\u8868&#xff09;\u201d \u4e0e \u201c\u539f\u5b50\u5316 CSS&#xff08;Tailwind CSS \/ UnoCSS&#xff09;\u201d \u662f\u5f53\u4e0b\u6700\u4e3b\u6d41\u7684\u4e24\u5927\u6280\u672f\u6d41\u6d3e\u3002<br \/>\n\u7136\u800c&#xff0c;\u5728\u5c06\u8fd9\u4e24\u5957\u65b9\u6848\u63a8\u5411 Vite \u751f\u4ea7\u6784\u5efa\u6253\u5305&#xff08;vite build&#xff09;\u65f6&#xff0c;\u5982\u679c\u7f3a\u4e4f\u5bf9\u5e95\u5c42<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[66,723,594,50,87],"topic":[],"class_list":["post-109427","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-react","tag-web","tag-50","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/109427.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636&#xff1a;CSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316\u5728\u73b0\u4ee3\u524d\u7aef\u5de5\u7a0b\u7684\u6837\u5f0f\u65b9\u6848\u9009\u578b\u4e2d&#xff0c;\u201cCSS Modules&#xff08;\u6a21\u5757\u5316\u6837\u5f0f\u8868&#xff09;\u201d \u4e0e \u201c\u539f\u5b50\u5316 CSS&#xff08;Tailwind CSS \/ UnoCSS&#xff09;\u201d \u662f\u5f53\u4e0b\u6700\u4e3b\u6d41\u7684\u4e24\u5927\u6280\u672f\u6d41\u6d3e\u3002 \u7136\u800c&#xff0c;\u5728\u5c06\u8fd9\u4e24\u5957\u65b9\u6848\u63a8\u5411 Vite \u751f\u4ea7\u6784\u5efa\u6253\u5305&#xff08;vite build&#xff09;\u65f6&#xff0c;\u5982\u679c\u7f3a\u4e4f\u5bf9\u5e95\u5c42\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/109427.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-23T19:48:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260923194842-6ab42d1a9a7eb.webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109427.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/109427.html\",\"name\":\"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-23T19:48:43+00:00\",\"dateModified\":\"2026-09-23T19:48:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/109427.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/109427.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109427.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/109427.html","og_locale":"zh_CN","og_type":"article","og_title":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636&#xff1a;CSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316\u5728\u73b0\u4ee3\u524d\u7aef\u5de5\u7a0b\u7684\u6837\u5f0f\u65b9\u6848\u9009\u578b\u4e2d&#xff0c;\u201cCSS Modules&#xff08;\u6a21\u5757\u5316\u6837\u5f0f\u8868&#xff09;\u201d \u4e0e \u201c\u539f\u5b50\u5316 CSS&#xff08;Tailwind CSS \/ UnoCSS&#xff09;\u201d \u662f\u5f53\u4e0b\u6700\u4e3b\u6d41\u7684\u4e24\u5927\u6280\u672f\u6d41\u6d3e\u3002 \u7136\u800c&#xff0c;\u5728\u5c06\u8fd9\u4e24\u5957\u65b9\u6848\u63a8\u5411 Vite \u751f\u4ea7\u6784\u5efa\u6253\u5305&#xff08;vite build&#xff09;\u65f6&#xff0c;\u5982\u679c\u7f3a\u4e4f\u5bf9\u5e95\u5c42","og_url":"https:\/\/www.wsisp.com\/helps\/109427.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-23T19:48:43+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260923194842-6ab42d1a9a7eb.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/109427.html","url":"https:\/\/www.wsisp.com\/helps\/109427.html","name":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-23T19:48:43+00:00","dateModified":"2026-09-23T19:48:43+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/109427.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/109427.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/109427.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Vite \u751f\u4ea7\u6784\u5efa\u8fdb\u9636\uff1aCSS Modules \u4e0e\u539f\u5b50\u5316 CSS \u4ea7\u7269\u4f18\u5316"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=109427"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109427\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=109427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=109427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=109427"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=109427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}