Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

javascript - 哪些运行时平台和版本已实现ES6模块并导入导出语法?(Which runtime platforms and versions have implemented ES6 modules and import export syntax?)

The syntax below:

(语法如下:)

import someModule from './some/path';

// DECLARE OR EXECUTE SOME STUFF

function fooBar() {
  return;
}

export const foo = 'bar';
export default fooBar;

I have always read in docs and tutorials that this is the ES6 import/export syntax .

(我一直在文档和教程中阅读到这是ES6导入/导出语法 。)

So I've always assumed that it came around along with the ES2015 (ES6) spec, right?

(因此,我一直认为它与ES2015(ES6)规范一起出现,对吗?)

But why is it not shown in the Kangax compatibility table?

(但是,为什么它在Kangax兼容性表中未显示?)

I cannot find it anywhere in the table.

(我在桌子上的任何地方都找不到它。)

How can I know which platforms/versions have implemented it?

(我怎么知道哪些平台/版本实现了它?)

https://kangax.github.io/compat-table/es6/

(https://kangax.github.io/compat-table/es6/)

在此处输入图片说明

  ask by cbdeveloper translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"Can I use" appears to have what you're looking for:

(“我可以使用”似乎具有您要查找的内容:)

https://caniuse.com/#feat=mdn-javascript_statements_import

(https://caniuse.com/#feat=mdn-javascript_statements_import)

Compatibility for desktop browsers:

(桌面浏览器的兼容性:)

  • Edge >= 16 (Oct 2017)

    (边缘> = 16(2017年10月))

  • Chrome >= 61 (Sep 2017)

    (Chrome> = 61(2017年9月))

  • Firefox >= 60 (May 2018)

    (Firefox> = 60(2018年5月))

  • Safari >= 10.1 (Mar 2017)

    (Safari> = 10.1(2017年3月))

  • Opera >= 47 (Aug 2017)

    (Opera> = 47(2017年8月))

For mobile browsers the info is a bit more limited, but the dates are likely in the same ballpark.

(对于移动浏览器,信息受到更多限制,但日期可能在同一范围内。)

Should you use ES6 imports in user code today?

(您今天应该在用户代码中使用ES6导入吗?)

Probably not if your application is intended to be used by a general audience, unless you're targeting a specific runtime that is known to support it.

(如果您的应用程序旨在供一般读者使用,则可能不会,除非您针对的是已知支持该应用程序的特定运行时。)

Give it a couple more years.

(再给它几年。)

What's commonly done instead is to use a bundler such as Webpack or FuseBox (I've personally had a great experience with the latter).

(相反,通常要做的是使用捆绑器,例如WebpackFuseBox (我个人对后者有很好的经验)。)

This way you can use the import syntax in your codebase, while the end user gets a single combined .js file which handles module imports/exports in a more compatible way.

(这样,您可以在代码库中使用导入语法,而最终用户将获得一个组合的.js文件,该文件以更兼容的方式处理模块的导入/导出。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...