requirejs-rails
requirejs-rails copied to clipboard
Support onBuildRead option
To support Angular.JS one has to prevent uglifier destroying the function arguments for dependency injection. One solution is to convert those arguments into a different uglier syntax that will prevail uglification. onBuildRead needs to be passed to r.js as a literal function, not a string that's what this pull request does.
Example usage:
modules:
- name: 'application'
onBuildRead: "function (moduleName, path, contents) { return require('ng-annotate')(contents, {add: true}).src;}"
requires installing ng-annotate
npm-install -g ng-annotate
@RushPL Thanks! Before I get around to this, can you say if your PR is related to this one?
It is but I added support for only one specific field that must be a function :)
@RushPL Can you explain how adding functions is the only solution? Is onBuildRead
a compile time concept or something like that?
I have never said it is the only solution but it is the only solution I know that can integrate with requirejs-rails. One could use grunt for example instead. Yes, it is purely compile/build time. It simply passes this raw function input input to rjs_driver.js
, this input can arbitrarily preprocess the code.
@RushPL Thanks for the explanation. Looks like the gem will have to accommodate functions to modify r.js
behavior in the near future.