requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Support onBuildRead option

Open Rush opened this issue 10 years ago • 5 comments

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

Rush avatar Oct 23 '14 15:10 Rush

@RushPL Thanks! Before I get around to this, can you say if your PR is related to this one?

carsomyr avatar Oct 23 '14 16:10 carsomyr

It is but I added support for only one specific field that must be a function :)

Rush avatar Oct 23 '14 16:10 Rush

@RushPL Can you explain how adding functions is the only solution? Is onBuildRead a compile time concept or something like that?

carsomyr avatar Oct 23 '14 16:10 carsomyr

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.

Rush avatar Oct 23 '14 16:10 Rush

@RushPL Thanks for the explanation. Looks like the gem will have to accommodate functions to modify r.js behavior in the near future.

carsomyr avatar Oct 23 '14 16:10 carsomyr