PatrickJS / angular-intercom

An Angular.js wrapper for Intercom.io providing a simple and familiar API for Angular Developer.
MIT License
89 stars 36 forks source link

Not works when used with webpack #31

Open Alex12321 opened 8 years ago

Alex12321 commented 8 years ago

I create the sample repo https://github.com/Alex12321/test-intercom In this case I need to run intercom after page loads. But nothing happens.

You can see code what I used at this file: https://github.com/Alex12321/test-intercom/blob/master/client/app/app.js

To run:

npm install
gulp serve
yjwong commented 8 years ago

According to my tests, it seems that the Intercom script is not even loaded from the CDN. Will continue to investigate.

(Correction: It is, but the ping endpoint isn't being hit)

derekstavis commented 8 years ago

The issue is that webpack allows using AMD, which is the first if case. You need to disable AMD in webpack:

Install imports loader:

npm install imports-loader

On your require statement:

require('imports?define=>false!angular-intercom')
bisol commented 8 years ago

Complementing @derekstavis answer, this did the trick:

import 'imports?this=>window&exports=>false&define=>false!angular-intercom'

This fools angular-intercom's module startup tests ("exports=>false&define=>false") and works around webpack's scoping ("this=>window")