OptimalBPM / angular-schema-form-dynamic-select

AngularStrap and AngularUI dynamic select implementation(static/sync/async/http, filters) for Angular Schema Form
MIT License
55 stars 45 forks source link

Your UMD wrapper doesn't play nice with webpack #89

Closed BurkovBA closed 7 years ago

BurkovBA commented 8 years ago

Guys, I'm on webpack and tried to use your module with bower.

Unfortunately, it begins with the following UMD-wrapper, which breaks the build with webpack:

;(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['angular-schema-form'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(require('angular-schema-form'));
  } else {
    root.angularSchemaFormDynamicSelect = factory(root.schemaForm);
  }
}(this, function(schemaForm) {

It attempts to require('angular-schema-form') from within angular-schema-form-dynamic-select.js and this is undesirable, because angular-schema-form has multiple mains and thus with webpack each main should be required manually as e.g. require(angular-schema-form/schema-form), not just require(angular-schema-form):

  "main": [
    "dist/schema-form.js",
    "dist/bootstrap-decorator.js"
  ],

Moreover, with webpack require(angular-schema-form) is unneeded, as angular-schema-form has already been required in user's app.js, thus, it's available to angular-schema-form-dynamic-select as an angular module via angular DI mechanism.

Do you know any UMD solution that avoids this problem for webpack? Thanks.

nicklasb commented 8 years ago

TBH, and obviously, I am not that great at UMD packaging, I would greatly appreciate any contributions in that area.. On 15 Jun 2016 14:40, "Boris Burkov" notifications@github.com wrote:

Guys, I'm on webpack and tried to use your module with bower.

Unfortunately, it begins with the following UMD-wrapper, which breaks the build with webpack:

;(function(root, factory) { if (typeof define === 'function' && define.amd) { define(['angular-schema-form'], factory); } else if (typeof exports === 'object') { module.exports = factory(require('angular-schema-form')); } else { root.angularSchemaFormDynamicSelect = factory(root.schemaForm); } }(this, function(schemaForm) {

It attempts to require('angular-schema-form') from within angular-schema-form-dynamic-select.js and this is undesirable, because angular-schema-form has multiple mains and thus with webpack each main should be required manually as require(angular-schema-form/schema-form):

"main": [ "dist/schema-form.js", "dist/bootstrap-decorator.js" ],

Moreover, with webpack require(angular-schema-form) is unneeded, as angular-schema-form has already been required in user's app.js, thus, it's available to angular-schema-form-dynamic-select as an angular module via angular DI mechanism.

Do you know any UMD solution that avoids this problem for webpack? Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues/89, or mute the thread https://github.com/notifications/unsubscribe/AIPBJ813gDvxczymGsNZnjYNn8xwFtP8ks5qL_LXgaJpZM4I2UEq .

BurkovBA commented 8 years ago

Actually, nevermind, I found a workaround. As you're distributing src/ folder with your bower package and it contains a non-wrapped version of your script, I can just require the non-wrapped version with require(angular-schema-form-dynamic-select/src/angular-schema-form-dynamic-select) and it should work fine.

Cheers!

nicklasb commented 7 years ago

Closing this now, please re-open if you do not feel the question has been answered sufficiently.