{"id":1579,"date":"2022-07-02T02:21:08","date_gmt":"2022-07-01T18:21:08","guid":{"rendered":"https:\/\/fromideatocreation.com\/?p=1207"},"modified":"2023-07-02T16:36:37","modified_gmt":"2023-07-02T08:36:37","slug":"%e3%80%90next-js-%e7%b3%bb%e5%88%97%e3%80%91%e8%b3%87%e7%94%a2%e3%80%81%e5%be%8c%e8%a8%ad%e8%b3%87%e6%96%99%e8%88%87css-7","status":"publish","type":"post","link":"https:\/\/fromideatocreation.com\/?p=1579","title":{"rendered":"\u3010NEXT.JS \u7cfb\u5217\u3011\u8cc7\u7522\u3001\u5f8c\u8a2d\u8cc7\u6599\u8207CSS 8"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6a23\u5f0f\u7684\u6280\u5de7<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u80fd\u6709\u7528\u7684\u6a23\u5f0f\u63d0\u793a\u3002<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528 classnames \u4f86\u5207\u63db classes<\/h3>\n\n\n\n<p><code>classnames<\/code> \u662f\u4e00\u500b\u7c21\u55ae\u7684\u51fd\u5f0f\u5eab\uff0c\u53ef\u8b93\u60a8\u8f15\u9b06\u5207\u63db\u985e\u540d\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528 <code>npm install classnames<\/code> \u6216 <code>yarn add classnames<\/code> \u5b89\u88dd\u5b83\u3002<\/p>\n\n\n\n<p>\u8acb\u67e5\u770b\u5176<a href=\"https:\/\/github.com\/JedWatson\/classnames\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u6587\u4ef6\">\u6587\u4ef6<\/a>\u4ee5\u7372\u53d6\u66f4\u591a\u8a73\u7d30\u8cc7\u8a0a\uff0c\u4f46\u9019\u662f\u57fa\u672c\u7528\u6cd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5047\u8a2d\u60a8\u8981\u5efa\u7acb\u4e00\u500b\u63a5\u53d7 <code>type<\/code> \u7684 <code>Alert<\/code> \u5143\u4ef6\uff0c\u8a72 <code>type<\/code> \u53ef\u4ee5\u662f <code>success<\/code> \u6216 <code>error<\/code>\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u5b83\u662f <code>success<\/code>\uff0c\u60a8\u5e0c\u671b\u6587\u672c\u984f\u8272\u70ba\u7da0\u8272\u3002 \u5982\u679c\u662f <code>error<\/code>\uff0c\u60a8\u5e0c\u671b\u6587\u672c\u984f\u8272\u70ba\u7d05\u8272\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u5148\u7de8\u5beb\u4e00\u500b CSS \u6a21\u7d44\uff08\u4f8b\u5982 <code>alert.module.css<\/code>\uff09\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"css\" class=\"language-css\">.success {\n  color: green;\n}\n.error {\n  color: red;\n}<\/code><\/pre>\n\n\n\n<p>\u4e26\u50cf\u9019\u6a23\u4f7f\u7528 <code>classnames<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import styles from '.\/alert.module.css';\nimport cn from 'classnames';\n\nexport default function Alert({ children, type }) {\n  return (\n    &lt;div\n      className={cn({\n        [styles.success]: type === 'success',\n        [styles.error]: type === 'error',\n      })}\n    &gt;\n      {children}\n    &lt;\/div&gt;\n  );\n}<\/code><\/pre>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u81ea\u5b9a\u7fa9 PostCSS \u914d\u7f6e<\/h3>\n\n\n\n<p>\u958b\u7bb1\u5373\u7528\uff0c\u7121\u9700\u914d\u7f6e\uff0cNext.js \u4f7f\u7528 <a href=\"https:\/\/postcss.org\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"PostCSS\">PostCSS<\/a> \u7de8\u8b6f CSS\u3002<\/p>\n\n\n\n<p>\u8981\u81ea\u5b9a\u7fa9 PostCSS \u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>postcss.config.js<\/code> \u7684\u9802\u5c64\u6587\u4ef6\u3002 \u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f <a href=\"https:\/\/tailwindcss.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Tailwind CSS\">Tailwind CSS<\/a> \u7b49\u51fd\u5f0f\u5eab\uff0c\u9019\u5c07\u975e\u5e38\u6709\u7528\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u6dfb\u52a0 Tailwind CSS \u7684\u6b65\u9a5f\u3002 \u9996\u5148\uff0c\u5b89\u88dd\u5957\u4ef6\u5305\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ npm install -D tailwindcss autoprefixer postcss<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\uff0c\u5efa\u7acb\u4e00\u500b <code>postcss.config.js<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">\/\/ postcss.config.js\nmodule.exports = {\n  plugins: {\n    tailwindcss: {},\n    autoprefixer: {},\n  },\n};<\/code><\/pre>\n\n\n\n<p>\u6211\u5011\u9084\u5efa\u8b70\u901a\u904e\u5728 <code>tailwind.config.js<\/code> \u4e0a\u6307\u5b9a <code>content<\/code> \u9078\u9805\u4f86<a href=\"https:\/\/tailwindcss.com\/docs\/content-configuration\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u914d\u7f6e\u5167\u5bb9\u6e90\">\u914d\u7f6e\u5167\u5bb9\u6e90<\/a>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">\/\/ tailwind.config.js\nmodule.exports = {\n  content: [\n    '.\/pages\/**\/*.{js,ts,jsx,tsx}',\n    '.\/components\/**\/*.{js,ts,jsx,tsx}',\n    \/\/ For the best performance and to avoid false positives,\n    \/\/ be as specific as possible with your content configuration.\n  ],\n};<\/code><\/pre>\n\n\n\n<p>\u8981\u4e86\u89e3\u6709\u95dc\u81ea\u5b9a\u7fa9 PostCSS \u914d\u7f6e\u7684\u66f4\u591a\u5167\u5bb9\uff0c\u8acb\u67e5\u770b <a href=\"https:\/\/nextjs.org\/docs\/advanced-features\/customizing-postcss-config\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"PostCSS \u7684\u6587\u4ef6\">PostCSS \u7684\u6587\u4ef6<\/a>\u3002<\/p>\n\n\n\n<p>\u8981\u8f15\u9b06\u958b\u59cb\u4f7f\u7528 Tailwind CSS\uff0c\u8acb\u67e5\u770b<a href=\"https:\/\/github.com\/vercel\/next.js\/tree\/canary\/examples\/with-tailwindcss\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"\u6211\u5011\u7684\u7bc4\u4f8b\">\u6211\u5011\u7684\u7bc4\u4f8b<\/a>\u3002<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528 Sass<\/h3>\n\n\n\n<p>\u958b\u7bb1\u5373\u7528\uff0cNext.js \u5141\u8a31\u60a8\u4f7f\u7528 <code>.scss<\/code> \u548c <code>.sass<\/code> \u64f4\u5c55\u540d\u532f\u5165 <a href=\"https:\/\/nextjs.org\/docs\/basic-features\/built-in-css-support#sass-support\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Sass\">Sass<\/a>\u3002 \u60a8\u53ef\u4ee5\u901a\u904e <a href=\"https:\/\/nextjs.org\/docs\/basic-features\/built-in-css-support#adding-component-level-css\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"CSS \u6a21\u7d44\">CSS \u6a21\u7d44<\/a>\u548c <code>.module.scss<\/code> \u6216 <code>.module.sass<\/code> \u64f4\u5c55\u540d\u4f7f\u7528\u5143\u4ef6\u5c64\u7d1a\u7684 Sass\u3002<\/p>\n\n\n\n<p>\u5728\u4f7f\u7528 Next.js \u5167\u5efa\u7684 Sass \u652f\u63f4\u4e4b\u524d\uff0c\u8acb\u52d9\u5fc5\u5b89\u88dd <code>sass<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ npm install -D sass<\/code><\/pre>\n\n\n\n<p>\u8981\u4e86\u89e3\u6709\u95dc Next.js \u7684\u5167\u5efa CSS \u652f\u63f4\u548c CSS \u6a21\u7d44\u7684\u66f4\u591a\u8cc7\u8a0a\uff0c\u8acb\u67e5\u770b <a href=\"https:\/\/nextjs.org\/docs\/basic-features\/built-in-css-support\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"CSS \u6587\u4ef6\">CSS \u6587\u4ef6<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u958b\u7bb1\u5373\u7528\uff0cNext.js \u5141\u8a31\u60a8\u4f7f\u7528 .scss \u548c .sass \u64f4\u5c55\u540d\u532f\u5165 Sass\u3002 \u60a8\u53ef\u4ee5\u901a\u904e CSS \u6a21\u7d44\u548c .module.scss \u6216 .module.sass \u64f4\u5c55\u540d\u4f7f\u7528\u5143\u4ef6\u5c64\u7d1a\u7684 Sass\u3002<\/p>\n","protected":false},"author":1,"featured_media":1165,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"qubely_global_settings":"","qubely_interactions":"","inline_featured_image":false,"_ti_tpc_template_sync":false,"_ti_tpc_template_id":"","footnotes":""},"categories":[164,106],"tags":[163,227,228,229],"class_list":["post-1579","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-next-js","category-106","tag-next-js","tag-postcss","tag-sass","tag-tailwind-css"],"acf":[],"aioseo_notices":[],"qubely_featured_image_url":{"full":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"portraits":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-540x320.png",540,320,true],"thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-150x150.png",150,150,true],"medium":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x189.png",300,189,true],"medium_large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",640,404,false],"large":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",640,404,false],"1536x1536":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"2048x2048":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"qubely_landscape":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"qubely_portrait":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-540x320.png",540,320,true],"qubely_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-140x100.png",140,100,true],"nazare_single_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_card_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-480x454.png",480,454,true],"nazare_widget_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true],"nazare_widget_first_thumb":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-350x206.png",350,206,true],"nazare_el_banner_left":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_el_banner_right":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-560x454.png",560,454,true],"nazare_el_post_400x376":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x376.png",400,376,true],"nazare_el_post_520x460":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-520x454.png",520,454,true],"nazare_el_post_500x335":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x335.png",500,335,true],"nazare_el_post_500x300":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x300.png",500,300,true],"nazare_el_post_655x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-655x454.png",655,454,true],"nazare_el_post_500x290":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-500x290.png",500,290,true],"nazare_el_post_416x278":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-416x278.png",416,278,true],"nazare_el_post_480x425":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-480x425.png",480,425,true],"nazare_el_post_635x640":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-635x454.png",635,454,true],"nazare_el_post_305x177":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-305x177.png",305,177,true],"nazare_el_post_400x400":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x400.png",400,400,true],"nazare_el_post_400x360":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x360.png",400,360,true],"nazare_el_post_416x416":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-416x416.png",416,416,true],"nazare_el_post_485x430":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-485x430.png",485,430,true],"nazare_el_post_700x467":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-700x454.png",700,454,true],"nazare_el_post_1000x581":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_1320x605":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"nazare_post_705x565":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-705x454.png",705,454,true],"nazare_post_400x265":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-400x265.png",400,265,true],"nazare_el_post_1248x630":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download.png",720,454,false],"woocommerce_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x300.png",300,300,true],"woocommerce_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-600x378.png",600,378,true],"woocommerce_gallery_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true],"shop_catalog":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-300x300.png",300,300,true],"shop_single":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-600x378.png",600,378,true],"shop_thumbnail":["https:\/\/fromideatocreation.com\/wp-content\/uploads\/2023\/05\/app-download-100x100.png",100,100,true]},"qubely_author":{"display_name":"Wen","author_link":"https:\/\/fromideatocreation.com\/?author=1"},"qubely_comment":0,"qubely_category":"<a href=\"https:\/\/fromideatocreation.com\/?cat=164\" rel=\"category\">Next.js<\/a> <a href=\"https:\/\/fromideatocreation.com\/?cat=106\" rel=\"category\">\u6559\u5b78<\/a>","qubely_excerpt":"\u958b\u7bb1\u5373\u7528\uff0cNext.js \u5141\u8a31\u60a8\u4f7f\u7528 .scss \u548c .sass \u64f4\u5c55\u540d\u532f\u5165 Sass\u3002 \u60a8\u53ef\u4ee5\u901a\u904e CSS ...","_links":{"self":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1579"}],"version-history":[{"count":1,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1579\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/posts\/1579\/revisions\/1619"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=\/wp\/v2\/media\/1165"}],"wp:attachment":[{"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fromideatocreation.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}