Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LYfirstday opened this issue Feb 23, 2019 · 4 comments
Open

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

LYfirstday opened this issue Feb 23, 2019 · 4 comments

Comments

@LYfirstday
Copy link

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

@gwuhaolin
Copy link
Owner

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

@LYfirstday
Copy link
Author

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

@LYfirstday
Copy link
Author

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

@DS0818
Copy link

DS0818 commented Dec 30, 2019

image
image

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

下图是tsconfig配置

image

你可以试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants