【发布时间】:2019-04-04 12:37:10
【问题描述】:
这是我的 repo 和现场演示 https://github.com/alechance/nuxt-lodash。我将 Nuxt 与 Vuetify + lodash-es 一起使用,当运行 npm run dev 并重新加载我的页面时,我得到了 SyntaxError: Unexpected token export 和 export default isArray;
【问题讨论】:
这是我的 repo 和现场演示 https://github.com/alechance/nuxt-lodash。我将 Nuxt 与 Vuetify + lodash-es 一起使用,当运行 npm run dev 并重新加载我的页面时,我得到了 SyntaxError: Unexpected token export 和 export default isArray;
【问题讨论】:
lodash-es 库的导入文件不会被babel 转译。为了解决这个问题,Nuxt.js 提供了手动指定应该通过transpile 选项转译的文件的选项。
将以下代码添加到nuxt.config.js 的build 部分:
build: {
transpile: [
'lodash-es'
],
// Other build options
}
【讨论】:
babel-plugin-transform-imports 测试Vuetify a la carte,但我仍然遇到这个错误。我刚刚更新了 github github.com/alechance/nuxt-lodash 中的 repo,我不明白这个问题...
babel-plugin-transform-imports 覆盖 transpile 配置。如果你想进行 tree-shaking,你可以使用最新版本的 nuxt 和官方 vuetify 推荐 a la carte。或者使用vuetify-loader,它会自动捆绑和拆分组件。或者甚至使用babel-plugin-lodash,作为另一种选择。
!important。看起来我的 CSS 在我的 <head> 中呈现在来自 vueitfy 的那些之前。您知道如何更改我的<head> 中的顺序,以便我的样式出现在 vuetify CSS 之后吗?我知道这超出了我最初的问题的范围......