ui-component-loader icon indicating copy to clipboard operation
ui-component-loader copied to clipboard

加上ui-component-loader就报错,无法解析文件类型

Open LYfirstday opened this issue 6 years ago • 4 comments

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') }, 依赖文件 image

期望antd按需加载;实际报错,无法解析的文件类型;不加ui-component-loader能正常运行 image

LYfirstday avatar Feb 23 '19 12:02 LYfirstday

include: path.resolve(__dirname, 'node_modules/antd') 需要改成你导入了antd的源码所在,也就是src目录

gwuhaolin avatar Feb 24 '19 01:02 gwuhaolin

image 不起作用,打包的时候还是把antd的所有东西都打进来了 我就只引了一个Button组件 image

LYfirstday avatar Feb 24 '19 06:02 LYfirstday

我发现在ts中引入antd,不关是解构赋值引入还是单文件引入,都默认从antd的一个dist文件引入,路径不起作用??

LYfirstday avatar Feb 24 '19 06:02 LYfirstday

image image

这是我的配置,你可以参考下,我是混合使用的,这两种方式都可以按需加载 image 下面这个图是没有按需加载 image 估计你配置有些问题

下图是tsconfig配置

image

你可以试试

DS0818 avatar Dec 30 '19 16:12 DS0818