skatejs / web-components

[DEPRECATED] - The frictionless way to use the webcomponents/webcomponentsjs polyfills.
MIT License
17 stars 4 forks source link

leverage @webcomponents polyfills and lazy-loading #48

Open Hotell opened 7 years ago

Hotell commented 7 years ago

So as I've mentioned, I've tested out skate 5.x with stable release of https://github.com/webcomponents/webcomponentsjs 1.x

It works with skate but there are few critical issues:

But fortunately for us, varial heelflip is a no brainer , so I wrote custom loader which we can include within this project.

If you're ok with this @treshugart I'll add it here -> so no Breaking changes, we can publish it under subpath so user can use it like : import { lazyLoadPolyfills } from '@skate/web-components/loader

here is implementation:

https://github.com/Hotell/skate-starter/pull/1/files#diff-576f47b45fccf9ab3b7a0a75876182e1

usage:

yarn add @webcomponents/webcomponentsjs
yarn add @skatejs/web-components
// polyfills.js
import { lazyLoadPolyfills } from '@skatejs/web-components/loader'

lazyLoadPolyfills().then(bootstrap);

 // app bootstrap
 function bootstrap() {
   return System.import('./main');
 }

main.jsx

import { h, render } from 'preact'
import 'custom-wc-library'

const App = ({content}) => (
  <div>
     <wc-menu/>
     <wc-content>
        {content}
      </wc-content>
     <wc-footer/>
   </div>
)

render( <App/>, root )
treshugart commented 7 years ago

I'm happy to have a breaking change here if it makes sense. Would be good to just import '@skatejs/web-components'; if it's easier. No imperative code then.

Hotell commented 7 years ago

yup, agreed

Hotell commented 7 years ago

also current @webcomponents cannot be minified with webpack and uglify when es5 adapter is used :-|

https://github.com/webcomponents/custom-elements/issues/100

Hotell commented 7 years ago

I'm happy to have a breaking change here if it makes sense. Would be good to just import '@skatejs/web-components'; if it's easier. No imperative code then.

so I didn't read your comment right :D there has to be imperative code if you wanna lazy load polyfills only in browsers which need them, as you can see in my example/PR

Hotell commented 7 years ago

so final solution is implemented here:

https://github.com/Hotell/skate-starter#bundlepolyfill-sizes

check this out pls @treshugart

charandas commented 7 years ago

@Hotell curious where SystemJS comes from for https://github.com/Hotell/skate-starter/blob/master/src/main.ts#L7, looked in package.json but couldn't find it.

Hotell commented 7 years ago

Don't get confused, that's just webpack, which uses nowadays import() for lazy loading, but since Typescript doesn't support import as function I have to stick with System.import alias.

treshugart commented 7 years ago

Typescript doesn't support import as function

That's quite unfortunate because that's where it seems specs are moving. Is there a way that we can leverage import and still have consumers use TypeScript?

treshugart commented 7 years ago

I generally don't do default exports but I think it would be nice here because then it's a little bit simpler for the consumer and they can call it whatever they want.

import fills from '@skatejs/web-components';
import app from './app';

fills().then(app);

I like this idea. It's unfortunate that it has to be imperative, but I don't see any way around it, either. Thanks for working on this! :)

deini commented 6 years ago

Sorry to revive this but damn just found this, and looks 💯.

Since this project is now marked as deprecated do you guys have any suggestions of how to sanely use @webcomponents's polyfills with webpack?