我正在構建白標應用程式。
我有一個資產檔案夾,其中包含每個品牌的一個影像檔案夾和一個字體檔案夾。
像這樣:
assets/
brand1/
fonts/
images/
img1.png
img2.png
img3.png
brand2/
fonts/
images/
img1.png
img2.png
img3.png
src/
我的想法是在 assets 檔案夾的根目錄下有一個 index.js,我可以根據我的環境檔案匯出相關的檔案夾集。
雖然我不確定如何實作這一目標。
任何提示?
(我擔心的是我不想在我的每個組件中都有環境調節)
uj5u.com熱心網友回復:
讓我們假設您有兩個環境;
.env.brand1 NAME=BRAND1
.env.brand2NAME=BRAND2
創建一個index.js檔案,它的代碼應該是這樣的;
const images = {
BRAND1: {
logo: require('./brand1/brand1Logo.jpeg')
},
BRAND2: {
logo: require('./brand2/brand2Logo.jpeg')
}
}
export default images;
您現在可以在任何檔案中使用影像;
... other imports
import images from '#assets/index'
export default function () {
...other code
<Image source={images[Config.NAME].logo} />
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/338330.html
標籤:javascript 反应 反应原生 模块
