W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Babel宏正在迅速獲得蒸汽作為一個(gè)功能齊全的選項(xiàng),以允許對(duì)零配置項(xiàng)目(如create-react-app)進(jìn)行高級(jí)代碼轉(zhuǎn)換
如果您的腳手架設(shè)置為bbel-plugin-macio,然后只需使用新的樣式組件/宏導(dǎo)入,而不是樣式組件:
import styled, { createGlobalStyle } from 'styled-components/macro'const Thing = styled.div`color: red;`const GlobalStyle = createGlobalStyle`body {color: 'white';}`
宏包含我們的Babel 插件的所有功能,同時(shí)允許未彈出的工具來處理構(gòu)建過程的 Babel 部分。
babel-plugin-macros使用cosmiconfig來閱讀它的配置,可以在導(dǎo)入文件目錄中以下任何文件中被定位到:
然后,您可以指定相同的選項(xiàng),我們的 babel插件樣式組件進(jìn)入:
// babel-plugin-macros.config.jsmodule.exports = {// ...// Other macros configstyledComponents: {pure: true,},}
有關(guān)詳細(xì)信息,請(qǐng)參閱實(shí)驗(yàn)配置的 babel-插件宏。
您可能希望確保對(duì)象在整個(gè)項(xiàng)目中始終從宏導(dǎo)入。這可以通過使用no-restricted-imports來自 Eslint 的規(guī)則:
"no-restricted-imports": ["error",{"paths": [{"name": "styled-components","message": "Please import from styled-components/macro."}],"patterns": ["!styled-components/macro"]}]
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: