ElementUI / babel-plugin-component

Modular element-ui build plugin for babel.
452 stars 96 forks source link

是否可以同时支持mint-ui和element-ui #34

Open rich1e opened 6 years ago

rich1e commented 6 years ago

.babelrc

{
  "presets": [
    [
      "env",
      {
        "targets": {
          "browsers": [
            "> 1%",
            "last 2 versions",
            "not ie <= 8"
          ]
        },
        "modules": false,
        "useBuiltIns": true,
        "debug": false
      }
    ],
    "es2015",
    "stage-2"
  ],
  "plugins": [
    "transform-vue-jsx",
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ],
    [
      "component",
      [
        {
          "libraryName": "mint-ui",
          "style": true
        }
      ]
    ]
  ]
}
tengmaoqing commented 6 years ago

我分析了下, 示例是错误的。多个lib的时候,引用方式应该是 这个形式: ["component", [{ "libraryName": "element-ui", "styleLibraryName": "theme-chalk" }, { "libraryName": "mint-ui", "style": true }]],

yoyo837 commented 6 years ago

@tengmaoqing 也是有问题的 nuxt/nuxt.js#1603

xiaoxin-sky commented 6 years ago

@yoyo837 楼上这种方法是可行的!我测试后很是吃惊。完全没报错了! "plugins": [ ["component", [{ "libraryName": "mint-ui", "style": true }, { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" }] ]

emorlasar commented 6 years ago

@1912820899 你的babel-loader什么版本?.plugins[0][1] must be an object, false, or undefined 还是报错

tengmaoqing commented 6 years ago

@emorlasar "babel-loader": "^7.1.1", "babel-plugin-component": "^1.1.0", 和babel-loader 应该没关系。 我是直接看的 babel-plugin-component 源码发现要那么写的

AiPacinoDebug commented 5 years ago

@1912820899 你的babel-loader什么版本?.plugins[0][1] must be an object, false, or undefined 还是报错

plugins: [
    [
      'component',
      {
        libraryName: 'element-ui',
        styleLibraryName: 'theme-chalk'
      },
      'element-ui'
    ],
    [
      'component',
      {
        libraryName: 'mint-ui',
        style: true
      },
      'mint-ui'
    ]
  ]
Evis5 commented 5 years ago

我分析了下, 示例是错误的。多个lib的时候,引用方式应该是 这个形式: ["component", [{ "libraryName": "element-ui", "styleLibraryName": "theme-chalk" }, { "libraryName": "mint-ui", "style": true }]],

亲测这样子写也有问题,跑起来倒是没有报错,但打包的时候第二个按需引入没有减少体积,只有第一个按需引入减少了体积,怎么解决

Evis5 commented 5 years ago

@yoyo837 楼上这种方法是可行的!我测试后很是吃惊。完全没报错了! "plugins": [ ["component", [{ "libraryName": "mint-ui", "style": true }, { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" }] ]

你没有测打包后的体积吧,打包第二个没有起到按需引入的作用,即使按需引入也会把整个包打包进去,无语啊,怎么写都不行

yoyo837 commented 5 years ago

饿了么都不维护了,不想往这方面考虑了...

Evis5 commented 5 years ago

饿了么都不维护了,不想往这方面考虑了...

element-ui在维护呀,我自己开发了一个组件库my-ui, 我想在项目中同时按需引入my-ui和element-ui始终不行啊,急需大神帮助

yoyo837 commented 5 years ago

@elvis5 我说的是饿了么不维护这个babel插件了

Evis5 commented 5 years ago

@elvis5 我说的是饿了么不维护这个babel插件了

那怎么整,有其他方案?

yoyo837 commented 5 years ago

自己写一个兼容插件

Evis5 commented 5 years ago

自己写一个兼容插件

不行诶,还没那个能力哦

yoyo837 commented 5 years ago

看一下babel插件文档,会写js就行,执行环境是node.js,不难,难的是迈出这一步