我让它与我的配置一起工作,你能试试这些吗:
tsconfig.json:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"target": "esnext",
"moduleResolution": "node",
"jsx": "react",
"pretty": true,
"noEmit": true,
"strict": true,
"isolatedModules": true,
"esModuleInterop": true
},
"include": ["./src/**/*"]
}
.babelrc
{
"presets": [
"@babel/react",
"@babel/typescript",
[
"@babel/env",
{
"modules": false,
"targets": { "browsers": "last 2 versions" }
}
]
],
"plugins": [
[
"babel-plugin-styled-components",
{
"pure": true
}
],
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
和 webpack.config.js:
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
}
]
},
],
有了这些配置,我就可以对正常的死代码和样式组件进行树摇动(这有点像要开始工作,注意插件设置!)
环境:
node 8.10
"webpack": "^4.28.4",
"typescript": "^3.3.3",
"babel-loader": "^8.0.5",
"babel-plugin-styled-components": "^1.10.0",
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",