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

webpack 版本4.28.3, antd v3.11.6, babel7 按需加载无效 #298

Closed
Hyg900928 opened this issue Jan 8, 2019 · 20 comments
Closed

webpack 版本4.28.3, antd v3.11.6, babel7 按需加载无效 #298

Hyg900928 opened this issue Jan 8, 2019 · 20 comments

Comments

@Hyg900928
Copy link

@Hyg900928 Hyg900928 commented Jan 8, 2019

我的babel配置如下:typescript 版本是v3.2.2
image
启动之后样式没有生效:
image

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 8, 2019

查了好久的资料都没有解决, 这个问题网上说的用ts-import-plugin 解决我也试了,但是还是无效
image
image

@afc163
Copy link
Contributor

@afc163 afc163 commented Jan 8, 2019

- styles
+ style

image

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 8, 2019

@afc163 改了,还是无效
image

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

我的tsconfig.json 配置如下,不知道是不是我的ts配置有问题啊
image

@afc163
Copy link
Contributor

@afc163 afc163 commented Jan 9, 2019

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

@afc163 我已经按照你的意思改了, 按需加载还是无效,tsconfg.json 配置如下:

image

代码如下:

image

执行结果如下:

image

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

没有任何的报错信息

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

@afc163 @sorrycc webpack 部分配置如下:
image
image

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

如果我自入口处引入css 文件, 样式就可以出来了
image

但是这样的话,不是把整个css 文件都加载过来了吗,就不符合按需加载了吧?

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 9, 2019

@afc163 麻烦给讲解一下啦

@sorrycc
Copy link
Member

@sorrycc sorrycc commented Jan 9, 2019

参考 https://github.com/umijs/umi-examples/blob/master/typescript/tsconfig.json 配 tsconfig.json 试试,需要确保文件交给 babel-plugin-import 之前是 esm 的。

@summer789
Copy link

@summer789 summer789 commented Jan 14, 2019

@afc163 @sorrycc 我现在也遇到这个问题了 babel7 以后,可以直接用babel来处理typescript , 上面提到的方法都试过,完全没用,

@summer789
Copy link

@summer789 summer789 commented Jan 14, 2019

@Hyg900928 问题解决了吗

@summer789
Copy link

@summer789 summer789 commented Jan 14, 2019

这样配置以后,正常了,你试试
@Hyg900928
1547464943374

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 15, 2019

@summer789 能截一下,完整的图吗, 我这边还没解决啊

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 15, 2019

@summer789 或者给个参考地址也行

@Hyg900928
Copy link
Author

@Hyg900928 Hyg900928 commented Jan 15, 2019

已经解决, 需要用awesome-typescript-loader 处理一次 ,然后在交给babel-loader, 这样就可以解决
image

@es3154
Copy link

@es3154 es3154 commented May 14, 2019

@Hyg900928 可以把你的完整配置发一份吗?我也遇到同样的问题

@sorrycc sorrycc closed this May 14, 2019
@es3154
Copy link

@es3154 es3154 commented May 14, 2019

babel7 使用ts 使用@babel/preset-typescript
参考这个配置https://github.com/microsoft/TypeScript-Babel-Starter
https://juejin.im/post/5c822e426fb9a04a0a5ffb49

@kokoroX
Copy link

@kokoroX kokoroX commented Oct 30, 2019

babel7 使用ts 使用@babel/preset-typescript
参考这个配置https://github.com/microsoft/TypeScript-Babel-Starter
https://juejin.im/post/5c822e426fb9a04a0a5ffb49

解决了吗

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

Successfully merging a pull request may close this issue.

None yet
6 participants