基于创建ts项目暴露webpack-config文件
首先进入webpack.config.js文件,找到alias,新增别名
alias: {// Support React Native Web// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/'react-native': 'react-native-web',// Allows for better profiling with ReactDevTools...(isEnvProductionProfile && {'react-dom$': 'react-dom/profiling','scheduler/tracing': 'scheduler/tracing-profiling',}),...(modules.webpackAliases || {}),// 这里新增+ '@': path.resolve(__dirname, '../src')},
找到tsconfig.json文件,没有的话可以创建一个,下面是我自己的配置
{"compilerOptions": {"target": "esnext","module": "esnext","moduleResolution": "node","importHelpers": true,"jsx": "react","esModuleInterop": true,"sourceMap": true,"baseUrl": "./","strict": true,+ "paths": {+ "@/*": ["src/*"],+ },"allowSyntheticDefaultImports": true},"include": ["src/mock/**/*","src/**/*","config/**/*","typings.d.ts","images.d.ts"]}
在compilerOptions下新增paths内容,就可以正常使用@/路径了
第二次配置,第一次很久之前找了很多教程各种配置都有(然后还没成功!),相对还是觉得这种比较方便,记录下,方便下次使用
