nuxt babel_Nuxt:添加Babel插件

nuxt babel

I recently wanted to use the nullish coalescing operator in the code of my Nuxt application. Of course, I needed to include the Babel plugin in order to support that, but for some reason I couldn’t find how to do that right away. Thus, I’m writing this brief guide to have it as a reference for myself and for anybody else that needs to do it in the future.

最近,我想在Nuxt应用程序的代码中使用无效的合并运算符 。 当然,我需要包括Babel插件以支持该功能,但是由于某种原因,我无法立即找到该方法。 因此,我正在编写此简要指南,以供我自己以及将来需要使用它的任何其他人参考。

The first thing to do is to install the babel plugin with npm to enable the usage of the nullish coalescing operator

首先要做的是使用npm安装babel插件,以启用无效合并运算符的使用

npm install --save-dev @babel/plugin-syntax-nullish-coalescing-operator

Once you have that, according to the guide Babel guide you need to add this on the configuration file:

一旦有了这些,根据Babel指南,您需要将其添加到配置文件中:

{  
"plugins": ["@babel/plugin-syntax-nullish-coalescing-operator"]
}

But surprise! Nuxt didn’t have a babel configuration file. However, after some research, I found out that we have to do this on the nuxt.config.js file, and it’s pretty straightforward. Just look for the build property, which is at the root level of the module.exports object, and add your plugin there:

但是惊喜! Nuxt没有babel配置文件。 但是,经过一番研究,我发现我们必须在nuxt.config.js文件中执行此操作,这非常简单。 只需在module.exports对象的根目录下查找build属性,然后在其中添加插件即可:

module.exports = {  build: {    "plugins": ["@babel/plugin-syntax-nullish-coalescing-operator"]
}
}

And that’s all. You can keep using the newest and greatest syntax of Javascript.

就这样。 您可以继续使用最新的Java语法。

翻译自: https://medium.com/swlh/nuxt-adding-babel-plugins-f288b1ad6304

nuxt babel

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 根据引用\[1\],你的请求到https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json失败了,原因是读取时发生了ECONNRESET错误。这可能是由于网络连接问题或服务器问题导致的。你可以尝试重新发送请求或检查你的网络连接。 根据引用\[2\],当你执行npm install -g create-nuxt-app时,你想要创建buxt文件,但是遇到了一个错误。错误信息显示create-nuxt-app.ps1文件无法加载,因为在你的系统上禁用了运行脚本。你可以参考提供的链接了解有关执行策略的更多信息。这个问题可能是由于你的系统设置或权限问题导致的。你可以尝试更改执行策略或以管理员身份运行命令来解决这个问题。 关于你提到的Error: \[BABEL\] F:\web\vue\vue-nuxt\.nuxt\client.js: --- PLACEHOLDER PACKAGE ---,这个错误信息并没有提供足够的上下文来确定具体的问题。请提供更多的错误信息或上下文,以便我能够更好地帮助你解决这个问题。 #### 引用[.reference_title] - *1* *2* [nuxt.js搭建踩坑及各种报错问题解决方案](https://blog.csdn.net/qq_43429963/article/details/127495392)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值