iVis-at-Bilkent / cytoscape.js-context-menus

A Cytoscape.js extension to provide context menu around elements and core instance
MIT License
87 stars 41 forks source link

Add webpack configuration #47

Closed onsah closed 4 years ago

onsah commented 4 years ago

This pull request adds webpack configuration and removes gulp file. Webpack bundles separate javascript files into one. Allowing the programmer to write more structured code while deploying single file. Babel plugin adds the ability to use modern js features too. Functionality of gulp replaced by npm commands.

hasanbalci commented 4 years ago

@onsah It seems good, but I noticed a problem during cytoscape registration that is sourced from Babel v6 usage. The problem is same with the one described here. I think Babel 6 changes the way it exports default, so it requires to add .default while using extension as CommonJs module (let contextMenus = require('cytoscape-context-menus').default;) which isn't desired to provide backward compatibility. Hence, we either can use a plugin like this, or we can write registration part by using CommonJS require and module.exports. Can you please search in more detail and apply the appropriate solution for this?

onsah commented 4 years ago

Sorry about that. I should have tested it. I did some research and best and simplest way seems to use es modules inside the project but only export as CommonJS module. From there webpack should handle other module definitions such as amd. I made the necessary changes so that it exports using module.exports instead of export default. I tested the library it works with require in node js projects.

hasanbalci commented 4 years ago

@onsah In this case, do we need babel-plugin-add-module-exports in package.json?

onsah commented 4 years ago

@hasanbalci We don't. I have removed it right now.