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

怎么动态使用babel-plugin-component这个插件 #36

Open
jackieveev opened this issue May 12, 2018 · 9 comments
Open

怎么动态使用babel-plugin-component这个插件 #36

jackieveev opened this issue May 12, 2018 · 9 comments

Comments

@jackieveev
Copy link

如题,我近期用到了elementui,因为觉得很好用,就把我之前项目整个替换成该UI库,但是现在遇到一个问题,希望各位大大给点帮助,因为网络上实在没有找到相关问题。
我的项目里有两个入口文件,index.js和login.js,对应两个html。
因为登录页只用到少许组件,所以我就想在login页使用babel-plugin-component这个插件,但index.js里是照常引入。
import Vue from 'vue';
import ElementUI from 'element-ui';
Vue.use(ElementUI);
这个时候babel-plugin-component就会报错
ERROR in ./src/app.js
Module build failed: Error: C:/Users/kuo/Desktop/vue-projects/gk/src/app.js: [babel-plugin-component] If you are using bothon-demand and importing all, make sure to invoke the importing all first.
at importMethod (C:\Users\kuo\Desktop\vue-projects\gk\node_modules\babel-plugin-component\lib\core.js:103:21)

请问有什么配置或方法是可以动态使用babel-plugin-component这个插件的吗?感激不尽。

@huhaophp
Copy link

huhaophp commented Jun 5, 2018

I got the error too.

[babel-plugin-component] If you are using bothon-demand and importing all, make sure to invoke the importing all first.

@daskyrk
Copy link

daskyrk commented Jun 7, 2018

我也碰到了,不过是新增babel-plugin-lodash插件时报的,后来发现是用nuxt hmr时直接修改编译配置会报这个错,停掉服务重新编译就没了

@daskyrk
Copy link

daskyrk commented Jun 23, 2018

run dev时可以,build时又不行了。。

@daskyrk
Copy link

daskyrk commented Jun 23, 2018

查了下原因,插件报错位置:https://github.com/ElementUI/babel-plugin-component/blob/master/src/core.js#L85
这里中间少了个空格,应该是using both on-demand and importing all,指全量引入import Element from 'element-ui'和单独引入import { Message } from 'element-ui'都有时,需要把全量引入的代码放在前面


我的情况是nuxt的plugins中引入了axios和element-ui:

  plugins: [
    '~/plugins/element-ui.js',
    '~/plugins/axios.js',
  ],

在axios.js中单独引入了Message,在element-ui.js中是全量引入的。
把element-ui放在了前面,报错了,然后换了下位置:

  plugins: [
    '~/plugins/axios.js',
    '~/plugins/element-ui.js',
  ],

就可以了,怀疑这里的plugin是逆序加载的,真实情况没有深究,知道的同学请告诉我一下。

@jackieveev
Copy link
Author

是不是没人维护这个插件了呀?

@johnlin0207
Copy link

我是删除了.babelrc 下的plugins/component解决的。

@Sherryer
Copy link

Sherryer commented Apr 3, 2020

相同场景:多入口,一个入口全量依赖、一个入口按需加载。
相同问题。

@cxrwdnx
Copy link

cxrwdnx commented Oct 22, 2020

我是删除了.babelrc 下的plugins/component解决的。

我也是

@TaHongLingBo
Copy link

have you tried restart

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

7 participants