Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM/ES6 module format #124

Open
cdalexndr opened this issue Jul 14, 2021 · 6 comments
Open

ESM/ES6 module format #124

cdalexndr opened this issue Jul 14, 2021 · 6 comments

Comments

@cdalexndr
Copy link
Contributor

Please provide esm format distribution for importing in browser directly without any module loader.

@wilsonpage
Copy link
Owner

wilsonpage commented Jul 16, 2021 via email

@imperatormk
Copy link

Is this still relevant/needed? Maybe can offer some help.

@TheAwesome98-Real
Copy link

TheAwesome98-Real commented Feb 10, 2022

Not sure what this means but happy to accept a PR

It lets you do this:

<script type="module">
import { FastDom } from '/path/to/fastdom';

EDIT: in JS you use the export keyword to allow import to import it like this

// file1.js

export const a = "A!";
export const b = "B :D";
export const c = "C :)";
export const d = "D :3";

// file2.js

// this is just an example of ways import can be used
import {a, b}, * from 'file1.js';

@WebMechanic
Copy link

WebMechanic commented Jun 23, 2022

I believe that defeates the purpose of the library.
As a module it would be encapsulated and other code could not reach it, but this is meant to be a global singleton.

@VitorLuizC
Copy link

I believe that defeates the purpose of the library. As a module it would be encapsulated and other code could not reach it, but this is meant to be a global singleton.

Every ESM module works like a singleton, so no problem.

@WebMechanic
Copy link

Every ESM module works like a singleton, so no problem.

@VitorLuizC Do not make assumptions about whether it is a problem or not. Your personal perspective and needs do not apply to everone. Web project vary and it is an issue if you don't have modules all the way through.
Please try to be more open minded.

Right now it is one global instance accessible from every scope which some may require if they can't/won't rewrite their codebase.

<head>
  <script src="./js/fastdom.min.js"></script>
  <script type="module">
    /* use within a (new) module */
    console.log( window.fastdom );
  </script>
</head>
<body>
<script>
  /* use within "old" code */
  console.log( window.fastdom );
</script>
</body>

Anyway you can (already) use this as module.

import "./fastdom.min.js"
console.log(fastdom);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants