question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web-compatible ES module build

See original GitHub issue

Hey @developit! I was wondering if you would be open to a new build that is ES modules compatible for the web? I have a branch of this working locally. It uses a small custom babel plugin that turns stuff like './util' into './util.js';

It works in Safari:

screen shot 2017-04-25 at 10 34 22 am

In my branch I run the babel plugin and put everything into dist/es/. This took me like 5 minutes, super easy. If you are open to adding this, there are a couple of options:

dist/es or some such folder

This would be the way I did it for my proof of concept. This means that browser users would use Preact with something like:

import { Component } from './node_modules/preact/dist/es/preact.js';

This would require no changes to your src/ codebase. If you wanted to keep src/ the way it is, this is the way to go.

preact.js in root folder

A bit nicer solution for web users would be if you added preact.js to the root folder and all it did was:

export * from './src/preact.js';

Or it could point to './es/dist/preact.js'. If you are willing to change your src/ modules to add the .js at the end and point to exact files in that way, then no Babel transformations would be needed.

Users would only have to do:

import { Component } from './node_modules/preact/preact.js';

Which is just a tiny bit easier.

Let me know what you think! cc @treshugart

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
matthewpcommented, Apr 26, 2017

Why ES5? If someone is using this bundle they are either using a module-compat browser or are using a build tool where they can transpile how they wish, right?

2reactions
robertknightcommented, Apr 26, 2017

The ES2015 source de-opts, I wouldn’t recommend using it.

Is that an issue specific to Chrome? If so, does it still apply when using the new V8 engine (Ignition + TurboFan) I wonder?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web-compatible ES module build · Issue #670 · preactjs/preact
I was wondering if you would be open to a new build that is ES modules compatible for the web? I have a...
Read more >
New in Vue: ES Module Browser Build
Vue 2.6 features an ES Module Browser Build, allowing you to write modular Vue apps that can run in the browser without a...
Read more >
Using ES Modules in the Browser Today - SitePoint
This article will show you how you can use ES modules in the browser today. Until recently, JavaScript had no concept of modules....
Read more >
Event loops - HTML Spec
Let script be the result of creating a JavaScript module script using source text , settings object , base URL , and options...
Read more >
nanobundle - npm
Yet another build tool for libraries, powered by esbuild ... and some meaningful proposals like ES Modules and Import maps which are already ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found