marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
142 stars 40 forks source link

marko-widgets by default pulling in marko runtime #99

Open senthilp opened 8 years ago

senthilp commented 8 years ago

marko-widgets by default is pulling in marko runtime due to this reference to ./defineRenderer. The first line in defineRenderer.js is require('marko').

Is this needed? If needed why is the package.json not having dependency on marko? There is only a devDependency

philidem commented 8 years ago

marko-widgets definitely requires the marko runtime (it would never be used without it). I think the reason that marko was not declared as a production dependency was so that the top-level project can declare the specific version of marko and it was assumed that that would satisfy the dependency.

However, I think it would be safe to move marko to the normal dependencies of the marko-widdgets module for clarity. The npm install command should only install marko once even if the top-level project and marko-widgets module both require it. The only time that you might see it installed twice is if you run npm install marko-widgets and then npm install marko for your project.

Anyways, I would say move marko to dependencies in the package.json.

senthilp commented 8 years ago

Thanks @philidem. Based on my conversation with @patrick-steele-idem the marko-runtime is only be needed when there is client side rendering. Which makes sense, as the marko dependency is only there in the defineRenderer.js file. In our (eBay) pages, most of them are server side rendered. If that is the case why should we include the marko-runtime in the JS that is sent to the browser? Is there any other use of the marko-runtime to be needed in the browser?

Is it possible to have the client side rendering JS packaged separately in marko-widgets?

patrick-steele-idem commented 8 years ago

Hey @senthilp, defineRenderer() is for rendering so it will have a hard dependency on marko since marko is used for the view. Marko Widgets lets you split the renderer and widget into separate files. If you go the split renderer/widget route and you are only rendering on the server then you would only send down the widget to the browser (not the renderer) and the renderer would be used on the server. The renderer would be defined using the defineRenderer() method and the widget would defined using the defineWidget() method. The defineWidget() method does not bring in the marko runtime.

patrick-steele-idem commented 8 years ago

Also, please see: http://markojs.com/docs/marko-widgets/get-started/#split-renderer-and-widget

senthilp commented 8 years ago

But @patrick-steele-idem having this line in the main marko-widget file, will make the lasso optimizer bundle the 'marko-runtime' too along with the widget library. Even if I split the renderer and widget it would not make a difference in the final generated JS file.