Taro - 別名引入路徑方式

config/index.js

const path = require('path') // eslint-disable-line
const config = {
  alias: {
    '@/api': path.resolve(__dirname, '..', 'src/api'),
    '@/components': path.resolve(__dirname, '..', 'src/components'),
    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
    '@/store': path.resolve(__dirname, '..', 'src/store')
  }
}

tsconfig.js

"paths": {
  "@/api": ["src/api"],
  "@/components": ["src/components"],
  "@/assets": ["src/assets"],
  "@/store": ["src/store"],
}

參考:
https://www.jianshu.com/p/634ecb0fbf3e
https://nervjs.github.io/taro/docs/config-detail.html#alias

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章