-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack and angular-cli support #185
Comments
Breeze is written with a universal module header, that allows it to be loaded globally as well as via a module loader such as SystemJS or a module bundler such as webpack. You just need to properly import breeze-client and datajs in your Angular app and it should bundle fine with webpack. We use breeze with webpack in several projects ourselves, without having to mess with the webpack configuration. See our Angular bridge for more info: https://github.com/Breeze/breeze.bridge.angular2 and this post should help with how to import datajs. http://stackoverflow.com/questions/39352922/breezejs-angular-2-and-odata/39356264#39356264 |
Hi Marcel, Even I have spent many hours over last 4-5 months on same issue. We cannot use the solution suggested by you because of following:
I would be looking at the change @kferstl has mentioned above too. But I would request that if that change is feasible - kindly consider due to above reasons. |
Just beautifying original fix offered by @kferstl . (function (global, definition) {
var def = function(){ return definition(global); };
// CommonJS
if (typeof exports === "object" && typeof module === "object") {
// CHANGE STARTED BY @kferstl
global = window;
// CHANGE COMPLETE BY @kferstl
module.exports = def();
// RequireJS
} else if (typeof define === "function" && define["amd"]) {
define(def);
// <script>
} else {
breeze = def();
}
})(this, function (global) { |
I would probably need a small repro sample to see the issue that you are describing. I have a suspicion that the root cause is somewhere else based on your comments. Here's why. breeze.debug.js is already a bundle of breeze and all the adapters. That's why it has the I had to do a similar thing for https://github.com/Breeze/temphire.angular2/tree/master/TempHire In rollup.js, I use the alias plug-in (webpack has a similar plug-in) and set up an alias for breeze-client like so:
And then in my app I manually import all the required adapters.
and configure them manually
We are working on breeze-vnext and a beta should be available soon. It's rewritten entirely in TypeScript and uses modern module management. I'm reluctant to changing the module header of current breeze. This is a standard universal header that is used in other libraries as well and so far we haven't seen any issues with it in several angular 2 projects, but again, none have an OData back-end, so there could be an issue that we haven't experienced ourselves yet. |
Tried all these options... But get same errors. May be what you say about datajs throwing in wrench might be true. I will try to provide an isolated small repo for debugging. |
@marcelgood, I also had the same issue when using Angular CLI with BreezeJS & datajs. in I just created a demo project that solves the issue by tweaking Also I had to modify "Readme" also contains how to see the error but let me know if you encounter any issue. Update: Created a separate issue and updated the demo app |
@coni2k thanks! This solution worked for me. It's not the best to have to live patch a library like this, but it's better to do this than to modify breeze-client directly. @marcelgood I believe this rollup PR if completed would fix this problem and you should be able to update to the latest rollup and solve this problem properly. Edit: I had some issues with Q even with this change and had to set it later. If someone runs into the same issue, try adding the following to your initialization: import * as Q from 'Q';
import { config } from 'breeze-client';
config.setQ(<any>Q); |
Breeze wraps its definition in a function and sees "this" as its global variables. For my understanding, this does not work in combination with angular-cli. angular-cli uses uses webpack and it looks like "this" is an empty object instead of the global namespace when using webpack. The result is, that breeze is unable to find any depending library like OData (datajs).
My (very) dirty fix:
breeze.debug.js
`
(function (global, definition) {
var def = function(){ return definition(global); };
})(this, function (global) {
....
`
I found some other workarrounds in combination with webpack, e.g. this:
http://stackoverflow.com/questions/41119357/how-to-configure-webpack-to-support-global-window-for-breeze-clientdatajs
The problem with angular-cli is, that it does not and will not expose the webpack configuration, so this is no solution.
The text was updated successfully, but these errors were encountered: