如何使Webpack接受可选的链接而无需babel [英] How to make webpack accept optional chaining without babel
问题描述
场景:
- 我们正在使用webpack 4从我们的Javascript来源创建一个包.
- 我们不使用Babel,因为我们仅针对单个平台(最新的Chrome)进行创作,并且仅使用Chrome中直接可用的功能,因此无需进行转换./li>
- 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.
这样做的好处是,较小的包,并且在开发时更快的周转时间.
The plus side of this is a smaller bundle, and much faster turnaround times while developing.
现在,我们想开始使用阶段4 可以使用标记在Chrome中启用.
Now we would like to start using the stage 4 optional chaining feature which can be enabled in Chrome using a flag.
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的答案有关,橡子今天发布了支持可选链接的新版本.一旦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屋!