Created
July 13, 2018 12:45
-
-
Save vuuvv/32db3eb6fab70f1639a7676b13b11128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
我这边能成功的按需加载,主要有下面几点你们可以参考一下: | |
代码里面的引用方式使用下面这种 | |
```ts | |
import { Button } from 'antd'; | |
``` | |
tsconfig.json | |
```json | |
{ | |
"compilerOptions": { | |
"outDir": "build", | |
"target": "es6", | |
"lib": ["es6", "dom"], | |
"sourceMap": true, | |
"allowJs": true, | |
"jsx": "preserve", | |
"moduleResolution": "node", | |
"rootDir": "src", | |
"forceConsistentCasingInFileNames": true, | |
"noImplicitReturns": true, | |
"noImplicitThis": true, | |
"noImplicitAny": false, | |
"strictNullChecks": true, | |
"suppressImplicitAnyIndexErrors": true, | |
"allowSyntheticDefaultImports": true, | |
"noUnusedLocals": true | |
}, | |
"exclude": [ | |
"node_modules", | |
"build", | |
"scripts", | |
"acceptance-tests", | |
"webpack", | |
"jest", | |
"src/setupTests.ts" | |
], | |
"types": [ | |
"typePatches" | |
] | |
} | |
``` | |
"target": "es6" 是为了将ts输出成es6再交给babel处理 | |
"jsx": "preserve" 是为了保持 jsx 格式输出,由 babel 做 jsx 转换,这个直接写成 react 由 ts 转也没什么问题。 | |
.babelrc | |
```json | |
{ | |
"presets": ["es2015", "react", "stage-0"], | |
"plugins": [ | |
"add-module-exports", | |
"transform-runtime", [ | |
"import", [ | |
{ | |
"style": "css", | |
"libraryName": "antd" | |
} | |
] | |
] | |
] | |
} | |
``` | |
webpack.config.js 里面则是要注意把ts的输出交给babel | |
```json | |
{ | |
test: /\.(ts|tsx)$/, | |
include: paths.appSrc, | |
loader: 'babel!ts', | |
}, | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment