如何让 webpack 在没有 babel 的情况下接受可选链接 [英] How to make webpack accept optional chaining without babel
问题描述
场景:
- 我们正在使用 webpack 4 从我们的 Javascript 源创建一个包.
- 我们不使用 Babel,因为我们仅针对单一平台(最新版 Chrome)进行创作,而且我们仅使用 Chrome 中直接可用的功能,因此不需要转译.
- We're using webpack 4 to create a bundle from our Javascript sources.
- We're not using Babel because we're authoring only for a single platform (latest Chrome), and we're only using features directly available in Chrome, thus no transpiling is required.
这样做的好处是较小的捆绑,开发时的周转时间.
现在我们想开始使用阶段 4 可选链功能 可以使用标志在 Chrome 中启用.
Now we would like to start using the stage 4 optional chaining feature which can be enabled in Chrome using a flag.
我试着用谷歌搜索这个,我能找到的就是 babel 有一个插件.
I've tried to google this, and all I was able to find is that babel has a plugin for this.
问题:有什么办法可以让 webpack 接受这种语法同时省略 babel 吗?
以下是 webpack 当前报告的内容:
Here's what webpack currently reports:
ERROR in ./src/js/components/custom-select.js 245:12
Module parse failed: Unexpected token (245:12)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| */
| focus() {
> this.input?.focus();
| return this;
| }
@ ./src/js/components/components.js 16:0-49 16:0-49
推荐答案
关于@Klaycon 的回答,Acorn 今天发布了一个支持可选链接的新版本.一旦 Webpack 反映了他们的变化 - 使用 webpack 的可选链接应该不再是问题.
Relating to @Klaycon's answer, Acorn released today a new version that supports optional chaining. As soon as Webpack reflects the change on their side- using optional chaining with webpack shouldn't be a problem anymore.
这篇关于如何让 webpack 在没有 babel 的情况下接受可选链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!