HubSpot / messenger

Growl-style alerts and messages for your app. #hubspot-open-source
http://github.hubspot.com/messenger/
MIT License
4.02k stars 405 forks source link

can it support webpack? #113

Closed elvismacak closed 6 years ago

elvismacak commented 8 years ago

I meet a problem in using webpack.

unitedworx commented 8 years ago

it works here in webpack but I cant for the life of me define default options for every Messenger() call. if it specific them in each call it works but not globally.

akarelas commented 7 years ago

How did you do make it work with webpack? what did you write in webpack.config.js?

unitedworx commented 7 years ago

This is how I use it and works!

require ("messenger/build/js/messenger");
Messenger.options = {
    extraClasses: 'messenger-fixed messenger-on-top',
    theme: 'block',
    messageDefaults: {
        showCloseButton: true,
        hideAfter: 4
    }
};    

nothing special was need in webpack.config.js

akarelas commented 6 years ago

But that's a bit complicated! It should be as simple as: import Messenger from 'messenger';

akarelas commented 6 years ago

@elvis-macak ^^

elvismacak commented 6 years ago

Yes, it can be.

But also you can add an alias in webpack config, like


    extensions: ['.js', '.vue', '.json'],
    alias: {
      'messenger$': 'messenger/build/js/messenger.js',
    }
  },```

@akarelas  hope it can work for you. 
akarelas commented 6 years ago

Why us (the many) do that, and not you make your module to work with just: import Messenger from 'messenger' ?

elvismacak commented 6 years ago

If you add the alias,then you can import messager directly, the code you mentioned will work

Alexander Karelas notifications@github.com 于 2018年3月24日周六 22:58写道:

Why us (the many) do that, and not you make your module to work with just: import Messenger from 'messenger' ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/HubSpot/messenger/issues/113#issuecomment-375895291, or mute the thread https://github.com/notifications/unsubscribe-auth/AEzh5Dj4mwHtaK__UH0lE1R8gb4yp6wAks5thl76gaJpZM4IzIgB .

--

Best regards,

Elvis

akarelas commented 6 years ago

I don't know, I'm used to doing this: npm import some-module and then in my Vue code, to just write: import Messenger from 'some-module';.

Can't we have that?

elvismacak commented 6 years ago

It's a magic, haha

If you use import Vue from "vue", while the "vue" is an alias for "vue/dist/vue.esm.js"

You can see that in webpack.base.js if using vue-cli webpack template.

Alexander Karelas notifications@github.com 于 2018年3月25日周日 10:55写道:

I don't know, I'm used to doing this: npm import some-module and then in my Vue code, to just write: import Messenger from 'some-module';.

Can't we have that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/HubSpot/messenger/issues/113#issuecomment-375941472, or mute the thread https://github.com/notifications/unsubscribe-auth/AEzh5CU7yuT-QFge25TIyNh8S8fWsUgWks5thwcagaJpZM4IzIgB .

--

Best regards,

Elvis

akarelas commented 6 years ago

For 99.9999% of the modules it is not necessary to modify the webpack config file to work with simply:

import BlaBla from 'bla-bla';
console.log(BlaBla);

For 99.999%. But you think there's nothing wrong with requiring the user to edit the webpack config to do the same?

The only reason vue has an alias in webpack config (already pre-written, the user doesn't need to do anything about it) is that production vue and development vue are different files.

Do you really want the user to have to edit the webpack config to use your module?

elvismacak commented 6 years ago

I know that, but I'm not sure whether this project is still under maintained.

If it's not maintained, and you still want your code to be clean like import BlaBla from 'bla-bla';, you have to update the webpack config file.

Or you can fork this project, that's also not the best way.

elvismacak commented 6 years ago

I add a pr https://github.com/HubSpot/messenger/pull/129, hope the maintainer can merge it back

akarelas commented 6 years ago

will import Messenger from 'messenger' pollute the windows.* namespace? Other modules don't pollute it, but I'm not so sure what messenger does...