-
Notifications
You must be signed in to change notification settings - Fork 2
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 should we manage dependencies? #4
Comments
HTML Imports are also being contested by Mozilla and they will not implement them. They propose the use of ES6 modules instead. "Mozilla will not ship an implementation of HTML Imports. We expect that once JavaScript modules — a feature derived from JavaScript libraries written by the developer community — is shipped, the way we look at this problem will have changed." ECMAScript 6 provides the following ways of importing: // Default exports and named exports
import theDefault, { named1, named2 } from 'src/mylib';
import theDefault from 'src/mylib';
import { named1, named2 } from 'src/mylib';
// Renaming: import named1 as myNamed1
import { named1 as myNamed1, named2 } from 'src/mylib';
// Importing the module as an object
// (with one property per named export)
import * as mylib from 'src/mylib';
// Only load the module, don’t import anything
import 'src/mylib'; |
I'm hoping for an ES6 module solution. Currently SystemJS and Web Components are very tangential. |
@greenify, If I understand correctly the four options above are regarding html imports. But html imports is not a necessity of web components. From https://hacks.mozilla.org/2015/06/the-state-of-web-components/:
Using SystemJS might be something to look into. |
SystemJS as a module loaderAdded a new branch for this test: Loading module in .js System.import('../../d3/d3.min.js').then(function() {
Polymer({
... Loading SystemJS in index.html <script src="../../systemjs/dist/system.js"></script> Dependencies listed in bower.json "dependencies": {
"polymer": "Polymer/polymer#^1.0.0",
"d3": "~3.5.6",
"systemjs": "https://github.com/systemjs/systemjs.git#0.18.4"
}, https://github.com/herkulano/biojs3-webcomponent-example/blob/dependency-systemjs/bower.json#L23 It still depends on bower to install all dependencies, i.e., the end-user still has to use bower to install the dependencies. Any thoughts? |
I also find the ES6 module specification quite tempting - especially if we have a loader like SystemJS that supports AMD, CommonJS and ES6 modules. However we still would require a common structure to be able to avoid duplications when loading modules?
I have created an example that gets all internal dependencies and Polymer from SystemJS. https://github.com/greenify/polymer-systemjs-loading Unfortunately it also doesn't solve the problem that we have if someone imports third-party dependencies like |
@greenify we are working on the same thing. SystemJS knows where the modules are based on the System.config.js. Using jspm this is automatic.
then in the module you can:
|
It is additionally complicated if you want to use bundling. SystemJS builder won't bundle into html files. |
Here is one way to bootstrap a Web Component using SystemJS: http://plnkr.co/edit/w3L3FB I used commonjs because I couldn't get traceur working in plunker. |
@Hypercubed That's a really cool example! 👍 It also shows that developers can use whatever flavour they want and still comply with Polymer > Web Components (in the near future). |
Thanks. Here is one more demo before I call it a night: http://plnkr.co/edit/JJp6jp Here I made a dumb systemjs plugin to do the HTML importing. This allows you to use mappings in the system.config.js (and all module loading goodness). I haven't tested it much so I don't know how robust it is. I can imagine that it could be a lot smarter and process inline css and js for you. I'm surprised it hasn't been done before. |
@Hypercubed Amazing! 👍 |
@Hypercubed I like your approach - it is more secure than mine ;-) Here a few remarks that I have by looking through your code: Injecting html via systemjs-plugin-htmlAFAIK using this approach is problematic when you bundle everything, as
Injecting css via relative linksWe probably can't bundle
using systemjs pluginsI guess that we need to agree on all the custom plugins of systemjs that we want to use as for a development setup as we probably want to avoid requiring a bundled version in other packages - we would have hard time to filter out duplicates. In summaryThe biggest difference between our two approaches is that you (1) dynamically add For convenience I have put my current version onto plunkr, too: http://plnkr.co/edit/CbZXA1?p=preview |
You are correct. Bundling wont work. The css plugin has it's own mechanism for bundling that I did not implement. The inline css and js are NOT processed at all by systemjs. At this point, as shown in my last plunker, I'm using the plugin as a promise generator. But maybe with some work... |
@greenify Also amazing! 👍 |
Found this... https://github.com/nevir/html-exports/tree/master/dist/sysjs-plugin Haven't had a chance to look in detail. |
@greenify nice I've forked @greenify's plunk and added some abstraction as a bio.js library to simplify the module loaders for developers: http://plnkr.co/edit/mEKZ2r?p=preview Some problems of this solution:
Are we planning to have several versions: ES5, ES6, HTML? UPDATE: I've merged your ideas in this plunker http://plnkr.co/edit/g54ESw?p=preview |
For me, as a potential BioJS3 module consumer, I am happy using jspm/SystemJS/ES6. I think, however, npm/Browserify/CommonJS has more traction currently and may be more familiar to BioJS2 users and developers. The Web Components/Polymer way seams to be to forget modules, throw everything into bower and reference via relative path. That approach of course limits what modules you can consume. Would it even allow you to import an existing BioJS2 io module from npm? That said, I think it is more than possible to create a BioJS3 template that provides all three. Write your code in ES6 and html, generate an ES5/UMD module, generate a HTML Import file that uses relative paths. Provide a I think that would be amazing. |
@herkulano I don't think we want to be using the System.import directly, this wont work for bundling. I took your plunker and added and es6 module, a generated (by hand) es5 commonjs file, and a pure web component html import file. Only the ES5 module is being used but should show a way we can provide all three. http://plnkr.co/edit/gwnVq9 |
Relevant discussion: http://www.codequora.com/questions/25005623/web-components-polymer-and-systemjs Wondering if we need/want Polymer/HTML imports at all. |
It is absolutely great to work with you on this :)
Have you seen this great talk by @guybredford (the author of jspm) on how jspm can be used to manage {es6,es5} dependencies from {github,npm} - he also showcases a cool demo with web components!
I do imagine two ways:
Wow 👍 - I am only a bit afraid that
(: , but if we decide to go for html imports we would need to find a way to run vulcanize on top of the systemjs bundle. That is why I personally would prefer if the JavaScript version would require the html and css -I need to find a better way than innerHTML tough ;-)
👍 - wondering about the same! |
Yeah, keeping the version numbers in sync between |
@Hypercubed looks great! |
Some findings on using JSPM with PolymerI've added another branch, wanted to try jspm, so couldn't use plunker for this. Polymer Elements From paper-button.html <link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../paper-behaviors/paper-button-behavior.html"> Bower Some problems:
|
Hey, I used our work @herkulano & @Hypercubed to create a jspm example app that uses the following web components as dependencies: In particular Currently
I guess we only
Feel free to modify the Happy hacking! |
Perhaps, but I don't see the API in there yet. What I mean is BioJS web components can use a component constructor that looks like Polymer:
|
If it is exactly the same... might as well use polymer. i.e. # 3 |
I don't know @greenify's plans on this. I agree if the library is the same there's no point in duplicating work. Although, i still have the concerns i mentioned before with using Polymer JS, unless the Polymer team embraces the idea of Polymer JS, which from @addyosmani's comments it's highly unlikely at least short-term. |
Polymer JS, if I understand what you mean, could be as simple as:
and require('polymer/polymer.html!html');
module.exports = Polymer; |
AFAIK, it doesn't work like that, because of Polymer's HTML Imports. That's why @greenify had to do a Polymer JS, extracting all of the html and importing polymer-mini.html and polymer-micro.html into one .js file. It would be good if you could test it so that we are sure of what we are saying. I'm not, so don't know if it works or not. 😄 |
Extracting the Polymer HTML to Javascript is already automated and do think that if we ask nicely they (Polymer) will accept a pull request because it is nothing they have to maintain. My opinion is that Angular 2 will have support for Web components. It will definitely come in other frameworks like React too or there will be new frameworks. So I don't think we should build our own polymer. We probably lack the resources to maintain it. However if a developer doesn't want to include the 150kb for Polymer he shouldn't need to. Thinking especially about the parsers it could make sense if we maintain our own lightweight library here because simply they don't need all the fancy features from polymer and all parsers are supposed to inherit from a common parent that we have to and want to maintain anyways. On July 13, 2015 2:02:12 PM GMT+02:00, Herculano Campos [email protected] wrote:
|
So you still have to update it and push it when they make changes or that is also automated?
Support for web components is not being questioned. Polymer is, which is not the same. That means you vote for 3, right? If we're going with 3 we should think about:
|
On 2015-07-13 14:50, Herculano Campos wrote:
Nope it is not triggered automatically, well we could add that.
Oh sorry - I was writing the message on my phone. I would prefer if we focus on the basic, Vanilla (#2) approach and find solutions based on this.
Also for approach II we have to solve some of those issue. E.g. we have to find our a documentation format/parser (see #9). |
@herkulano Using |
BTW, I am also testing this method of including scripts in HTML imports (ModuleLoader/es-module-loader#95). If it works (so far looks good) then we can import HTML files that contain inline ES6 (and dependencies). |
@Hypercubed Great work on systemjs-plugin-html, it's looking good 👍 |
@Hypercubed let me know if you need / want any help with the bundling. |
Hello guys, I've added unit tests and updated the html plugin to allow inline script modules. Rather than filling up this issue I created an issue here: Hypercubed/systemjs-plugin-html#2 . |
Here is a way to bridge SystemJS and polymer elements: https://github.com/Hypercubed/systemjs-plugin-html/tree/master/test/polymer |
@Hypercubed great work. didn't have time to check it out, will do it asap. |
Since it looks like we are leaning towards 2 or 3 with JSPM build. Perhaps we need some discussion of what this actually means. What is the expected output of a JSPM build step run on a biojs component? What about a JSPM build on a app that includes a biojs component? |
Here is an example polymer component that uses SystemJS for dependencies (using the SystemJS html plugin). This also demonstrates jspm bundling using the vulcanize branch of the plugin. |
@Hypercubed that's really great! 👍 I only have one concern, which might not be an issue for some people. Correct me if I'm wrong, but it's still difficult to use Polymer Elements with jspm, because of the HTML Import links. For example, paper-button.html looks like this: <link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../paper-behaviors/paper-button-behavior.html"> Because of the way bower's folder structure works they can get away with this link: We could change it at runtime and build time to point to the right folder, similar to what Any thoughts? |
The setup I've shown uses polymer as a helper, but doesn't need to, it can work on vanilla elements. To use polymer elements you can do what I showed here: https://github.com/Hypercubed/systemjs-plugin-html/tree/master/test/polymer . Basically, create a |
The biggest problem I am seeing is that if you incorporate two copies of the same HTML import with different urls (including polmer.html its self) HTML imports/vulcanize can't deduplicate, resulting in a runtime error. |
I am 100% behind option 2 |
Great work guys. But what is the final result? (I counted about half-dozen outgoing links + sample repos). What are my options? Is there a sample repo? Update: |
I'd also like to know the final result... |
I can't speak for BioJS but for me, there was too much flux and uncertainty around WC. |
If you haven't done so, please read this excellent article as an intro to the problem of dependency management in web components by @tjvantoll:
http://tjvantoll.com/2014/08/12/the-problem-with-using-html-imports-for-dependency-management/
@tjvantoll discusses the following options - for convenience shortly summarized here:
Option 1: Use a CDN
Option 2: Enforcing a folder structure on the end user + relative imports
The Polymer project is using this approach - here is the distribution guide for 0.5 written by @addyosmani.
Option 3: Feature detection
Summary: using a tiny module loader to detect whether the script has already been loaded
Option 4: Not using HTML imports for external dependencies
Summary: no reference in the component's code - the dependency is only referenced in the documentation
This also has been discussed at the Polymer project.
Here is my opinion to start the discussion: Option 2 (enforcing a common folder structure) seems to be the lesser evil.
However for dependency conflicts:
node_modules/<lib>/dist/<lib>.html
and../<lib>/dist/<lib>.html
)I am very much looking forward to your thoughts :)
The text was updated successfully, but these errors were encountered: