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

How to install and import #75

Closed
lastmjs opened this issue Aug 2, 2017 · 29 comments
Closed

How to install and import #75

lastmjs opened this issue Aug 2, 2017 · 29 comments

Comments

@lastmjs
Copy link

lastmjs commented Aug 2, 2017

Hi there, I'm excited to get going with hyperHTML. I think it would be nice for the readme to show exactly how to install and import hyperHTML, I'm not seeing that anywhere and I'm having to figure it out on my own. Thanks!

@WebReflection
Copy link
Owner

var hyperHTML = require('hyperhtml');

???

@WebReflection
Copy link
Owner

Alternatively

<!doctype html>
<script src="https://unpkg.com/hyperhtml@latest/min.js"></script>

@lastmjs
Copy link
Author

lastmjs commented Aug 2, 2017

What about import {hyperHTML} from './node_modules/hyperhtml/min';? Why doesn't that work?

@WebReflection
Copy link
Owner

WebReflection commented Aug 2, 2017

in which environment would that work?

it's not a native ES module, it misses .js

it's not a Webpack or Rollup import

so why do you think that should work at all?

The minified version is to include it like any other Web script.

<!doctype html>
<script src="https://unpkg.com/hyperhtml@latest/min.js"></script>

If you need the module, you need to npm install hyperhtml and then require it using whatever toolchain/wrapper/bundler you like, which should be compatible with regular npm modules.

@lastmjs
Copy link
Author

lastmjs commented Aug 2, 2017

I'm working with ES modules, I would love to expect to import my project like ES modules will allow in the future, and it is possible now. I'm pretty sure webpack and rollup allow it. I'm using Zwitterion.

@lastmjs
Copy link
Author

lastmjs commented Aug 2, 2017

I think it should be written as a native ES module, and then Webpack, Rollup, Zwitterion, etc, and eventually the native module loader will be able to load it.

@WebReflection
Copy link
Owner

I would love to expect to import my project like ES modules will allow in the future

in the future you will be able to do that.

I think it should be written as a native ES module

that's Web unfriendly. I do use CDN to bring in libraries, it's useful for CodePen examples and everything else.

That .min file is not what you want to import anyway, it's after bundlers and minification.

You want the native module, I understand, but you are using tools and these are smart enough to import modules from npm which has 70% of modules written in CommonJS, if not more.

TL;DR this ain't going to happen now because modules on npm are still published using npm language which is CommonJS

@lastmjs
Copy link
Author

lastmjs commented Aug 2, 2017

Okay, thank you for considering it, I understand. I hacked my way around it, in case you're interested:

import * as hyperHTMLRaw from './node_modules/hyperhtml/hyperhtml';
const hyperHTML = hyperHTMLRaw.default;

@WebReflection
Copy link
Owner

Last, but not least: in case you haven't noticed, this whole module is written in a JS compatible with every browser on this planet and it's small in size because of that.

Transpilers have the bad habit to blow code and these are annoying specially for little stand alone software like hyperHTML.

Writing this in latest/coolest ES syntax will:

  • drop compatibility with browser not supported by transpilers
  • increase 30% of the size for no reason whatsoever
  • decrease performance due wrapped functionalities that didn't really need to be wrapped
  • make bug report, test, maintenance a nightmare because I am aiming to 100% code coverage and having unreachable patterns due transpilers isn't exactly developer friendly

So, as you can see, the gain, compared with all the loss, isn't that worth it, isn't it?

However, the day npm modules will be compatible with ES2015 import exports I'll create in my build step a file that will just include export default hyperHTML; at the end of a copy and paste from the library.

Easy peasy, but not today 😉

@WebReflection
Copy link
Owner

WebReflection commented Aug 25, 2017 via email

@zwz
Copy link

zwz commented Aug 26, 2017

@WebReflection
I found the silly mistakes in my code just after I posted it. So I deleted it.
It is my fault. Sorry for the interuption.

I do not use HyperHTMLElement class because its document says that it requires IE 11 above.
But I have to support IE 9 at least, since they are still quite popular in my country.

@WebReflection
Copy link
Owner

I do not use HyperHTMLElement class because its document says that it requires IE 11 above.
But I have to support IE 9 at least,

This is a bit of a non-sense.

If you use classses and Custom Elements V1, you can forget IE9 because transpiled code will break there.

It's a long-standing, well documented and known, Babel bug.

My code works thanks to my Babel fix that inevitably needs IE11 or above so, if (classes) IE11+; else functions;

@zwz
Copy link

zwz commented Aug 26, 2017

Well, in this case I would use function instead, and no custom element.

@WebReflection
Copy link
Owner

You have examples here:
https://viperhtml.js.org/hyperhtml/examples/#!fw=React&example=Combined%20Components

The tricky bit is try to wire objects, recycling nodes.

But for all the one-off cases, I'd say you're good to go without classes.

@janat08
Copy link
Contributor

janat08 commented Jan 14, 2018

neither require nor import for "hyperhtml" works, even if npm home says otherwise.

@WebReflection
Copy link
Owner

@janat08 you are off topic and also wrong. Change tooling or address proper files/default

@janat08
Copy link
Contributor

janat08 commented Jan 15, 2018

I've got all the tooling that supports up to es7, and default doesn't do it.

@WebReflection
Copy link
Owner

You can require hyperhtml/cjs or import hyperhtml/esm

I’ve tons of online demo that just work via ESM so please try a bit harder, thanks

@janat08
Copy link
Contributor

janat08 commented Jan 15, 2018

I tried getting into node modules for the default in esm and my meteor app begun crashing.

@janat08
Copy link
Contributor

janat08 commented Jan 15, 2018

although what I suppose you mean in import "hyperhtml/esm" or require "hyperhtml/cjs"?

@WebReflection
Copy link
Owner

ESM

import hyperHTML from 'hyperhtml/esm';
// or
import {hyper, wire, bind, Component} from 'hyperhtml/esm';
// or
import hyperHTML from 'https://unpkg.com/hyperhtml?module';

CJS

const hyperHTML = require('hyperhtml/cjs').default;
// or
const {hyper, wire, bind, Component} = require('hyperhtml/cjs');

if none of these work for you I suggest you describe the tools you are using and the code you are writing.

@pmowrer
Copy link

pmowrer commented Jan 30, 2018

Would you consider providing an es5 build (or an UMD-wrapped version of min)? For those of us targeting browsers that don't understand es6, and don't yet transpile code in node_modules (including this library) during bundling (typical webpack build).

@WebReflection
Copy link
Owner

@pmowrer sounds like a reasonable request, please file an issue about it so I can address it. thanks.

@WebReflection
Copy link
Owner

@pmowrer never mind, it's here: https://unpkg.com/hyperhtml@latest/umd.js

you can also require("hyperhtml/umd") if you prefer

@pmowrer
Copy link

pmowrer commented Jan 30, 2018

@WebReflection That works great! Thanks for the quick turnaround!

@Lonniebiz
Copy link
Contributor

Lonniebiz commented Nov 26, 2018

ESM

import hyperHTML from 'hyperhtml/esm';
// or
import {hyper, wire, bind, Component} from 'hyperhtml/esm';
// or
import hyperHTML from 'https://unpkg.com/hyperhtml?module';

CJS

const hyperHTML = require('hyperhtml/cjs').default;
// or
const {hyper, wire, bind, Component} = require('hyperhtml/cjs');

if none of these work for you I suggest you describe the tools you are using and the code you are writing.

The official documentation should provide the content of this comment (especially the ESM part); it took me a while to find this.

@janat08
Copy link
Contributor

janat08 commented Nov 26, 2018

It's there at the bottom

@jordanaustin
Copy link

Here's the link straight to this section in the README: https://github.com/WebReflection/hyperHTML#installation

@Lonniebiz
Copy link
Contributor

Here's the link straight to this section in the README: https://github.com/WebReflection/hyperHTML#installation

I was looking for it here:
https://viperhtml.js.org/hyperhtml/documentation/#essentials-0

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

No branches or pull requests

7 participants