Inlining ECMAScript Modules in HTML

前端 未结 3 1928
情话喂你
情话喂你 2020-12-07 20:51

I\'ve been experimenting with new native ECMAScript module support that has recently been added to browsers. It\'s pleasant to finally be able import scripts directly and cl

3条回答
  •  忘掉有多难
    2020-12-07 21:10

    I don't believe that's possible.

    For inline scripts you're stuck with one of the more traditional ways of modularizing code, like the namespacing you demonstrated using object literals.

    With webpack you can do code splitting which you could use to grab a very minimal chunk of code on page load and then incrementally grab the rest as needed. Webpack also has the advantage of allowing you to use the module syntax (plus a ton of other ES201X improvements) in way more environments than just Chrome Canary.

提交回复
热议问题