最近項目要求配置 ts.如下是 ts 別名與 webpack 如何配置的方法
複製代碼
修改webpack配置文件與tsconfig文件;webpack
tsconfig.json:解析以後的相對路徑=》baseUrlVal+pathValweb
"baseUrl": ".",
paths": {
"@style/*": ["page/web/ts/main/test/components/style/*"],
"@model/*": ["page/web/ts/main/test/model/*"]
},
複製代碼
base.js:如下別名'@style','model'若也同時在tsconifg文件配置,則能夠在ts文件使用 import { ZZ } from "yy/zz" 導入, 若無,則只能在js|ts文件中 require('yy/xx')導入json
resolve: {
extensions: ['', '.js', '.jsx', ".ts", ".tsx"],
alias:
'biz-imgs': `${process.cwd()}/page/${platform}/${projectPath}/main/${pageName}/static/imgs`,
"testFold": `${process.cwd()}/page/${platform}/${projectPath}/main/${pageName}`,
'@style':`${process.cwd()}/page/${platform}/${projectPath}/main/${pageName}/components/style`,
'@model':`${process.cwd()}/page/${platform}/${projectPath}/main/${pageName}/model`,
}
},複製代碼