vant icon indicating copy to clipboard operation
vant copied to clipboard

nuxt配置base.css引入报错

Open winsan-zhang opened this issue 8 years ago • 5 comments

我使用的是nuxt1.4版本,进行ssr,按照vant官方文档配置 babel-plugin-import方式,在nuxt.config.js中配置babel-plugins,代码如下:

build: { babel: { "plugins": [ ["import", { "libraryName": "vant", style: true }] ] } } 然后页面中使用 import { Button } from 'vant'; Vue.use(Button) 编译未报错,渲染页面后报如下错误: 显示base.css存在 Unexpected token { 2018-03-23 14-55-37 不知是配置方式不对还是什么问题?

winsan-zhang avatar Mar 23 '18 07:03 winsan-zhang

目前 babel-plugin-import 和 nuxt 存在冲突,如果使用 nuxt 的话,建议手动按需引入组件~

chenjiahan avatar Mar 23 '18 12:03 chenjiahan

我也有相同的问题,手动引入还是有点难受

gongzhibin avatar Sep 20 '18 13:09 gongzhibin

这样配置就行


  build: {
   // 添加这个是关键,添加后babel才会处理依赖包vant里面的代码
    transpile: [ /vant.*?less/ ], 
   
    babel: {
      plugins: [
        ['import', {
          libraryName: 'vant',
          "style": (name) => {
            return `${name}/style/less.js`
          }
        }, 'vant']
      ],
    },
  }

具体参考我的文章: https://juejin.im/post/5e012778518825127f085da8

gp0320 avatar Dec 26 '19 03:12 gp0320

@gp0320 👍

chenjiahan avatar Dec 26 '19 05:12 chenjiahan

强烈建议在文档里标注下,开发环境没被覆盖,到了生产环境才发现字体样式都被覆盖

borie88 avatar Jul 26 '20 15:07 borie88