{"id":480,"date":"2025-12-05T10:36:07","date_gmt":"2025-12-05T02:36:07","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=480"},"modified":"2025-12-05T10:36:07","modified_gmt":"2025-12-05T02:36:07","slug":"vite%e4%b8%adsass%e8%ad%a6%e5%91%8ajs-api%e8%bf%87%e6%9c%9f%e7%9a%84%e5%8e%9f%e5%9b%a0%e5%8f%8a%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/vite%e4%b8%adsass%e8%ad%a6%e5%91%8ajs-api%e8%bf%87%e6%9c%9f%e7%9a%84%e5%8e%9f%e5%9b%a0%e5%8f%8a%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95\/","title":{"rendered":"vite\u4e2dsass\u8b66\u544aJS\u00a0API\u8fc7\u671f\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>Vite \u4e2d Sass \u62a5\u8b66\u544a \u201cJS API is deprecated\uff08Sass JS API \u5df2\u8fc7\u671f\uff09\u201d \u7684\u539f\u56e0 + \u6700\u7a33\u89e3\u51b3\u529e\u6cd5<\/strong>\uff0c\u57fa\u4e8e\u5f53\u524d\uff082025\uff09\u6700\u65b0\u7684 Sass \u4e0e Vite \u751f\u6001\u89c4\u8303\u6574\u7406\u3002<\/p>\n\n\n\n<p>\u8fd9\u4efd\u6307\u5357\u5305\u62ec\u6839\u672c\u539f\u56e0\u3001\u9519\u8bef\u793a\u4f8b\u3001\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3001\u672a\u6765\u8fc1\u79fb\u65b9\u5411\uff0c\u4e00\u770b\u5c31\u61c2\u3001\u9a6c\u4e0a\u80fd\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udea8 \u4e00\u3001\u4e3a\u4ec0\u4e48 Vite \u4e2d\u51fa\u73b0 Sass \u201cJS API deprecated\u201d \u8b66\u544a\uff1f<\/h1>\n\n\n\n<p>\u4ece <strong>Sass 1.77+<\/strong> \u5f00\u59cb\uff0c\u5b98\u65b9\u5ba3\u5e03\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u4f20\u7edf JavaScript API\uff08\u5982 render \/ renderSync \/ compile \/ compileString \u7b49\u65e7\u65b9\u5f0f\uff09\u5df2\u8fc7\u671f\uff08deprecated\uff09\uff0c\u672a\u6765\u4f1a\u88ab\u79fb\u9664\u3002<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>Vite \u7684\u6837\u5f0f\u5904\u7406\u94fe\u6761\u4e2d\uff0c\u901a\u5e38\u4f1a\u7531\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nVite \u2192 esbuild \/ rollup \u2192 sass \u2192 dart-sass \u2192 \u65e7 JS API\n\n<\/pre><\/div>\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff1a<br><strong>\u53ea\u8981\u4f60\u9879\u76ee\u4e2d\u7684\u67d0\u4e2a\u4f9d\u8d56\u5728\u8c03\u7528\u65e7 API\uff0c\u63a7\u5236\u53f0\u5c31\u4f1a\u51fa\u73b0\u8b66\u544a\u3002<\/strong><\/p>\n\n\n\n<p>\u5e38\u89c1\u89e6\u53d1\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sass-loader<\/code>\uff08\u5c11\u89c1\u4e8e Vite\uff0c\u4f46\u90e8\u5206\u63d2\u4ef6\u4f1a\u95f4\u63a5\u4f7f\u7528\uff09<\/li>\n\n\n\n<li><code>vite-plugin-style-import<\/code><\/li>\n\n\n\n<li><code>vite-plugin-sass-dts<\/code><\/li>\n\n\n\n<li>\u67d0\u4e9b UI \u6846\u67b6\u5185\u90e8 Sass \u7f16\u8bd1\uff08\u5982\u65e7\u7248 ElementPlus \/ Vuetify\uff09<\/li>\n\n\n\n<li>\u4f60\u81ea\u5df1\u4ee3\u7801\u4e2d\u4f7f\u7528 sass API\uff08\u5982 node-sass \u2192 dart-sass \u624b\u5199\u811a\u672c\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u6240\u4ee5\u5373\u4f7f\u4f60\u7684 vite.config.js \u6ca1\u6709\u6539\u52a8\uff0c\u4e5f\u4f1a\u5192\u51fa Warning\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u26a0\ufe0f \u8b66\u544a\u793a\u4f8b<\/h1>\n\n\n\n<p>\u63a7\u5236\u53f0\u901a\u5e38\u4f1a\u770b\u5230\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDeprecation Warning: The Sass JavaScript API is deprecated and will be removed in a future version.\nUse the new &#039;compile&#039; API instead.\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde9 \u4e8c\u3001Sass \u4e3a\u4f55\u5f03\u7528\u65e7 JS API\uff1f<\/h1>\n\n\n\n<p>\u539f\u56e0\u4e3b\u8981\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u65e7 API \u8bbe\u8ba1\u4e0d\u7edf\u4e00\uff08\u65e2\u6709 render \u53c8\u6709 compile\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u5f02\u6b65\/\u540c\u6b65\u884c\u4e3a\u6df7\u4e71\uff08renderSync \u5c06\u6d88\u5931\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u672a\u6765 Sass \u5c06\u66f4\u9760\u8fd1 WASM \u5b9e\u73b0\uff0c\u4e0d\u518d\u7ef4\u62a4\u65e7 Node.js \u63a5\u53e3<\/strong><\/li>\n<\/ol>\n\n\n\n<p>\u65b0\u7684 API \u66f4\u73b0\u4ee3\u7edf\u4e00\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sass.compile()<\/code><\/li>\n\n\n\n<li><code>sass.compileString()<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 \u4e09\u3001\u89e3\u51b3\u65b9\u6848\uff08\u6309\u4f18\u5148\u7ea7\u6392\u5e8f\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u2714\ufe0f \u65b9\u6848 1\uff1a\u5347\u7ea7 Sass \u5230\u6700\u65b0\u7248\u672c\uff08\u63a8\u8350\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm i -D sass@latest\n\n<\/pre><\/div>\n\n\n<p>\u4f46\u6ce8\u610f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5347\u7ea7 Sass \u5e76\u4e0d\u80fd 100% \u6d88\u9664\u8b66\u544a\uff0c\u56e0\u4e3a<strong>\u771f\u6b63\u8c03\u7528\u65e7 API \u7684\u5f80\u5f80\u662f\u201c\u4f60\u9879\u76ee\u91cc\u7684\u5176\u4ed6\u4f9d\u8d56\u201d<\/strong>\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u5373 Sass \u662f\u5bf9\u7684\uff0c\u4f46\u4f60\u7528\u7684\u63d2\u4ef6\u662f\u65e7\u7684\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2714\ufe0f \u65b9\u6848 2\uff1a\u5347\u7ea7 Vite \u63d2\u4ef6\u548c UI \u6846\u67b6<\/h1>\n\n\n\n<p>\u6700\u5173\u952e\u7684\u662f\u5347\u7ea7\u8c03\u7528 Sass \u7684\u63d2\u4ef6\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvite-plugin-style-import\nvite-plugin-sass-dts\nvite-plugin-vuetify\nvite-plugin-vue2\n@vitejs\/plugin-vue\n\n<\/pre><\/div>\n\n\n<p>\u793a\u4f8b\u5347\u7ea7\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm update\n\n<\/pre><\/div>\n\n\n<p>\u6216\u8005\u6307\u5b9a\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm i vite-plugin-style-import@latest -D\n\n<\/pre><\/div>\n\n\n<p><strong>\u5927\u90e8\u5206 2024 \u4ee5\u524d\u7684\u7248\u672c\u4ecd\u5728\u4f7f\u7528\u8fc7\u65f6\u7684 render() API\u3002<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2714\ufe0f \u65b9\u6848 3\uff1a\u68c0\u67e5\u662f\u5426\u4f7f\u7528\u4e86\u65e7\u7684 Node Sass API\uff08\u4f60\u81ea\u5df1\u7684\u4ee3\u7801\uff09<\/h1>\n\n\n\n<p>\u5982\u679c\u4f60\u6709\u811a\u672c\u624b\u52a8\u8c03\u7528 Sass\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport sass from &#039;sass&#039;;\n\nsass.render({file: &#039;xxx.scss&#039;}, () =&gt; {})\n\n<\/pre><\/div>\n\n\n<p>\u8fd9\u662f<strong>\u65e7 API<\/strong> \u2014\u2014 \u4f1a\u89e6\u53d1\u8b66\u544a\u3002<\/p>\n\n\n\n<p>\u6b63\u786e\u5199\u6cd5\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport sass from &#039;sass&#039;;\n\nconst result = sass.compile(&#039;xxx.scss&#039;);\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2714\ufe0f \u65b9\u6848 4\uff1a\u5f3a\u5236\u4f7f\u7528 WASM \u7248\u672c\u7684 Sass\uff08\u672a\u6765\u63a8\u8350\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm i -D sass-embedded\n\n<\/pre><\/div>\n\n\n<p>vite.config.js\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexport default {\n  css: {\n    preprocessorOptions: {\n      scss: { api: &#039;modern-compiler&#039; }\n    }\n  }\n}\n\n<\/pre><\/div>\n\n\n<p>\u26a0\ufe0f \u6ce8\u610f\uff1a\u53ea\u6709 Vite 5+ \u624d\u80fd\u8f83\u597d\u517c\u5bb9 embedded sass\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2714\ufe0f \u65b9\u6848 5\uff1a\u6682\u65f6\u5ffd\u7565\u8b66\u544a\uff08\u4e0d\u63a8\u8350\u4f46\u53ef\u884c\uff09<\/h1>\n\n\n\n<p>\u6709\u4e9b\u63d2\u4ef6\u4f5c\u8005\u8fd8\u6ca1\u6709\u5347\u7ea7\uff0c\u4ece\u5de5\u7a0b\u89d2\u5ea6\u4f60\u53ef\u4ee5\u6682\u65f6\u5ffd\u7565\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnode --no-warnings ...\n\n<\/pre><\/div>\n\n\n<p>\u4f46\u8fd9\u662f\u6743\u5b9c\u4e4b\u8ba1\uff0c\u4e0d\u63a8\u8350\u957f\u671f\u4f7f\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udfaf \u56db\u3001\u5982\u4f55\u5224\u65ad\u662f\u54ea\u4e2a\u4f9d\u8d56\u5bfc\u81f4\u7684 Sass API \u8fc7\u671f\u8b66\u544a\uff1f<\/h1>\n\n\n\n<p>\u4f7f\u7528\u547d\u4ee4\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm ls sass\n\n<\/pre><\/div>\n\n\n<p>\u627e\u51fa\u6240\u6709\u4f9d\u8d56 Sass \u7684\u5305\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u67d0\u4e2a\u5305\u4f9d\u8d56\u4e86 &#8220;node-sass&#8221; \u6216 &#8220;sass-loader@&lt;13&#8243;\uff1a<\/p>\n\n\n\n<p>\ud83d\udc49 \u4e00\u5b9a\u4f1a\u89e6\u53d1 deprecated \u8b66\u544a\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde8 \u4e94\u3001\u5e38\u89c1\u5bfc\u81f4\u8b66\u544a\u7684\u4f9d\u8d56\uff082025 \u6700\u65b0\uff09<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u4f9d\u8d56<\/th><th>\u662f\u5426\u4f1a\u89e6\u53d1\u65e7 API<\/th><th>\u89e3\u51b3\u529e\u6cd5<\/th><\/tr><\/thead><tbody><tr><td>node-sass<\/td><td>\u2714 \u4f1a<\/td><td>\u6362\u6210 dart-sass\uff08\u5373 sass\uff09<\/td><\/tr><tr><td>sass-loader 10 \u4ee5\u4e0b<\/td><td>\u2714 \u4f1a<\/td><td>\u5347\u7ea7\u5230 13+<\/td><\/tr><tr><td>vite-plugin-style-import 1.x<\/td><td>\u2714 \u4f1a<\/td><td>\u5347\u7ea7\u5230 2.x<\/td><\/tr><tr><td>\u65e7\u7248 Vuetify<\/td><td>\u2714 \u4f1a<\/td><td>\u7528\u5b98\u65b9 Vite \u63d2\u4ef6<\/td><\/tr><tr><td>element-plus &lt; v2<\/td><td>\u26a0\ufe0f \u90e8\u5206\u4f1a<\/td><td>\u5347\u7ea7 2.4+<\/td><\/tr><tr><td>\u65e7 rollup-sass \u63d2\u4ef6<\/td><td>\u2714 \u4f1a<\/td><td>\u66f4\u6362\u63d2\u4ef6\u6216\u5347\u7ea7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udfc6 \u516d\u3001\u6700\u7a33\u7684\u5b9e\u9645\u5de5\u7a0b\u89e3\u51b3\u65b9\u6848\uff08\u76f4\u63a5\u5957\u7528\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1\uff1a\u5347\u7ea7 Sass<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm i sass@latest -D\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2\uff1a\u5347\u7ea7\u5168\u90e8\u76f8\u5173\u63d2\u4ef6<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm update\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3\uff1a\u68c0\u67e5 node-sass \/ sass-loader \u662f\u5426\u5b58\u5728<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnpm ls node-sass\nnpm ls sass-loader\n\n<\/pre><\/div>\n\n\n<p>\u5982\u679c\u6709 \u2192 \u5220\u9664 + \u66ff\u6362\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4\uff1a\u7528 modern API\uff08\u5982\u4f60\u81ea\u5df1\u5199\u4e86 JS \u8c03\u7528 Sass\uff09<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5\uff1a\u786e\u4fdd Vite \u7248\u672c \u2265 5\uff08Sass 1.77+ \u5b98\u65b9\u63a8\u8350\uff09<\/strong><\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udf89 \u4e03\u3001\u603b\u7ed3\uff08\u6700\u7b80\u7248\uff09<\/h1>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u8b66\u544a\uff1f<\/strong><br>\u56e0\u4e3a Sass 1.77+ \u5e9f\u5f03\u65e7 JS API\uff0c\u800c Vite \u9879\u76ee\u4e2d\u7684\u67d0\u4e9b\u63d2\u4ef6\u8fd8\u5728\u7528\u3002<\/p>\n\n\n\n<p><strong>\u600e\u4e48\u5f7b\u5e95\u89e3\u51b3\uff1f<\/strong><br>\u5347\u7ea7 Sass + \u5347\u7ea7\u63d2\u4ef6 + \u675c\u7edd node-sass + \u4f7f\u7528 compile \u65b0 API\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd Vite \u4e2d Sass \u62a5\u8b66\u544a \u201cJS API is deprec&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/vite%e4%b8%adsass%e8%ad%a6%e5%91%8ajs-api%e8%bf%87%e6%9c%9f%e7%9a%84%e5%8e%9f%e5%9b%a0%e5%8f%8a%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-480","post","type-post","status-publish","format-standard","hentry","category-javascript"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=480"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/480\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/480\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}