nuxtjs Cannot use import statement outside a module

开发环境 nuxtjs+antd

之前是在plugins里直接整个引入antd,完美运行。但打包之后资源文件太大,打包了很多不需要的组件进去,于是安装并配置了babel-plugin-import

babel: {
    "plugins": [
    ["import", {
        "libraryName": "ant-design-vue",
        "libraryDirectory": "es",
        "style": true
    }]
    ]
},
loaders: {
    less: {
    lessOptions: {
        javascriptEnabled: true
    }
    }
},

引用方式改为

import Vue from 'vue'
import {Button} from 'ant-design-vue'
Vue.use(Button)

然后保存 刷新 报错

Cannot use import statement outside a module

又是各种姿势挑逗google,终于在文档中找到了解决办法。

transpile: [
    "ant-design-vue"
]

具体解释,https://nuxtjs.org/api/configuration-build#transpile

你可能感兴趣的:(nuxtjs Cannot use import statement outside a module)