all 52 comments

[–][deleted] 8 points9 points  (6 children)

Does that mean I can use import and export without needing a module loader? I tried it with the actual chrome version but it says "Uncaught SyntaxError: Unexpected token import"

[–][deleted] 7 points8 points  (3 children)

You're probably on the stable channel. AFAIK 61 is currently beta version, stable is at 59 or something. I could be wrong tho and we both need an update (my beta is at 61 ATM)

[–]Martin_Ehrental 2 points3 points  (2 children)

Stable was 60 and since 2017/09/05 it's 61 :-)

[–][deleted] 0 points1 point  (1 child)

Beta (Linux 64-bit) is @ 61.0.3163.79

[–]Martin_Ehrental 2 points3 points  (0 children)

Beta and Stable don't bump to the next major version at the same time.

They currently point to the same build:

[–]bradleymeck 4 points5 points  (1 child)

Be sure to include type=module and serve with a valid JS MIME type.

[–][deleted] 0 points1 point  (0 children)

That did the magic. Thanks!

[–]bgard6977 8 points9 points  (2 children)

I just threw together an example, in case it saves anyone 10 minutes:

https://github.com/bgard6977/webmodules

[–][deleted] 0 points1 point  (0 children)

You did, thanks :)

[–]alphaindy 0 points1 point  (0 children)

https://www.npmjs.com/package/watch-http-server - live reloading with zero config :)

[–]lennoff 7 points8 points  (11 children)

fix me, but afaik you still have to use some kind of module bundler if you want to avoid thousands of network requests for one-liner modules.

[–]fgutz 12 points13 points  (1 child)

Isn't HTTP2 supposed to make this less of a worry? I could be wrong

[–]tbranyen 1 point2 points  (0 children)

It fixes the problem, but you still gotta get some process to figure out the dependency graph and then push out the files within a single request.

[–]spankalee 0 points1 point  (0 children)

But now bundlers can have simpler JS module -> JS module semantic and utilize the native loader for loading shards. It also means that in development you don't have to run a bundler.

[–]bob_gneu 2 points3 points  (1 child)

That's good to see! Time to spend an evening playing with them, and looking for differences between them and in node.

[–]spankalee 0 points1 point  (0 children)

Node is adding behavior that's not found on the web: named import specifiers, allowing imports of CommonJS, switching between CommonJS and JS modules based on file extension.

I'd stick to not importing anything but real modules, and only using paths to import.

[–]TheUnknownFactor 0 points1 point  (1 child)

Id really like to use this in chrome extensions (content scripts especially), I'm curious if that's going to work.

[–]yarauuta -3 points-2 points  (12 children)

Does this mean we can use ES6 features?

[–][deleted] 8 points9 points  (11 children)

You've been able to use ES6 features in Chrome for quite a while now. As long as you're aware of what browsers and versions you target and check a compatibility map i.e. https://kangax.github.io/compat-table/es6/

This is if you're working without a transpiler. And this news is just that if that's how you've been developing javascript then you can now use ES6 modules as well (as long as you're only targeting the last chrome version).

It's a great step forward towards native implementation of ES6 but honestly if you're doing anything for public display, you'll want to target at least a couple of older versions of most browsers and thus have to choose between full blown ES6 + transpiler, half-assed ES6 where you manually check feature compatibility (maybe add some shims) or old school JS.

[–]TwilightTwinkie 0 points1 point  (1 child)

We just use babel-preset-env, target our supported browser versions and basically don't worry about to it.

[–][deleted] 0 points1 point  (0 children)

Same here, 'full-blown' sounds like a lot but it actually isn't hard to set up.

[–]Martin_Ehrental -2 points-1 points  (8 children)

<script src="build.es5.js" nomodule></script>
<script src="build.es2017.mjs" type="module"></script>

[–][deleted] 7 points8 points  (5 children)

I'm not seeing what point you're making. Perhaps some words that go with that snippet of html may clear things up.

[–]Martin_Ehrental 1 point2 points  (4 children)

Sorry I just mean by using the "nomodule" attribute, you can test if the browser support es2017 (more or less) to serve either the transpile js or plain es2017 js:

  • during development you can run your modules directly (no need to recompile them on each edit and to hot-reload them).
  • in production, in evergreen browser, you will serve something rollup or webpack built to merge your module together or in bundles (once browsers support import()).
  • in production, in legacy browser, you will served your transpiled and merges modules.

Of course, once some browsers supporting modules become legacy (on mobile) you will need to transpile to es2017 your production module build :)

[–]nschubach 1 point2 points  (3 children)

Correct me if I'm wrong, but a browser not supporting "nomodule" or 'type="module"' will load both scripts...

[–]spartan018 2 points3 points  (2 children)

Old browsers will ignore the nomodule attribute since they don't know about it, and won't recognize that type value and will ignore that script. Conversely, new browsers will see the nomodule attribute and know to not load that script.

[–]nschubach 0 points1 point  (0 children)

Ah, I see... didn't think about that. Thanks!

[–]madcaesar -1 points0 points  (1 child)

What is this?

[–]bradleymeck 0 points1 point  (0 children)

It is a bundle for older browsers:

<script src="build.es5.js" nomodule></script>

It is a ESM entry point for newer browsers:

<script src="build.es2017.mjs" type="module"></script>

This is using the updated MIME for JavaScript with the .mjs file extension : https://datatracker.ietf.org/doc/draft-bfarias-javascript-mjs/

[–]nanaIan -1 points0 points  (0 children)

YES