Implementing r.js optimisation

Implementing r.js optimisation to local and core.