vant icon indicating copy to clipboard operation
vant copied to clipboard

使用babel-plugin-import怎么把vant添加到nuxt

Open fanwenfu opened this issue 7 years ago • 7 comments

按照官方推荐配置,会报下图错误

nuxt.config.js

build: {
    babel: {
        plugins: [
             ['import', {
                    libraryName: 'vant',
                    libraryDirectory: 'es',
                    style: true
                }, 'vant']
            ]
        }
}

Screenshots

image

而如果按照以下方法配置,则没问题,但是这种做法会导致引入全局index.less文件过大,并且无法定制主题

nuxt.config.js

plugins: [
        "~/plugins/vant.js",
    ],
 babel: {
            "plugins": [
                ["component", {
                    "libraryName": "vant",
                    "libraryDirectory": "es",
                    style: false
                }]
            ]
        },

在plugins新建vant

import 'vant/lib/vant-css/index.less';

Environment

  • Device: mac
  • Browser: chrome
  • Vant Version: v1.6.7
  • nuxt Version: v2.4.5

fanwenfu avatar Mar 04 '19 10:03 fanwenfu

同问

750973092 avatar Mar 08 '19 10:03 750973092

你好,这个问题建议到 nuxt 仓库提问,因为这个问题本质上是由 nuxt 和 babel-plugin-import 两者不适配导致的,vant 这边无法提供出解决方案

chenjiahan avatar Mar 09 '19 07:03 chenjiahan

这个问题解决了吗 ?

whapply avatar Apr 12 '19 02:04 whapply

同问

JonSnow-JY avatar Dec 23 '19 06:12 JonSnow-JY

这个问题解决了吗 ?

没解决

fanwenfu avatar Dec 24 '19 08:12 fanwenfu

同问

并没解决

fanwenfu avatar Dec 24 '19 08:12 fanwenfu

可以解决: 参考我的文章:https://juejin.im/post/5e012778518825127f085da8

gp0320 avatar Dec 26 '19 03:12 gp0320