ui-component-loader
ui-component-loader copied to clipboard
加上ui-component-loader就报错,无法解析文件类型
tsconfig.json文件配置 { "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "module": "commonjs", "jsx": "react", "target": "es5", "declaration": true, "lib": ["es6", "es7", "dom", "esnext"], "moduleResolution": "node", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": true, "allowSyntheticDefaultImports": true, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "skipLibCheck": true, "noUnusedLocals": true, "experimentalDecorators": true, "removeComments": true }, "include": [ "./src/**/*" ], "exclude": [ "node_modules", "config", "scripts", "acceptance-tests", "webpack", "jest", "dist", "server" ] }
webpack.config.js文件部分配置
{
test: /.tsx?$/,
use: [
"ts-loader",
{
loader: 'ui-component-loader',
options: {
'lib': 'antd',
'style': 'style/index.css',
}
}
],
include: path.resolve(__dirname, 'node_modules/antd')
},
依赖文件
期望antd按需加载;实际报错,无法解析的文件类型;不加ui-component-loader能正常运行
include: path.resolve(__dirname, 'node_modules/antd')
需要改成你导入了antd的源码所在,也就是src
目录
不起作用,打包的时候还是把antd的所有东西都打进来了
我就只引了一个Button组件
我发现在ts中引入antd,不关是解构赋值引入还是单文件引入,都默认从antd的一个dist文件引入,路径不起作用??
这是我的配置,你可以参考下,我是混合使用的,这两种方式都可以按需加载
下面这个图是没有按需加载
估计你配置有些问题
下图是tsconfig配置
你可以试试