I'm trying to integrate ECMA6 into existing Angular project. And I'm looking for a best practise for some issues we have. All components (and we have a lot) have following file structure:
-app/
--components/
--somemodul/
--somemodul.mdl.js
--somemodul.drv.js
--somemodul.ctrl.js
--somemodul.srv.js
--somemodul.tmpl.html
-app.js
//somemodul.mdl.js
(function () {
angular.module('somemodul', []); //initiate module
})()
//somemodul.drv.js
(function () {
angular.module('somemodul')
.directive('someModuleDrv', someModuleDrv); //add to module
function someModuleDrv() {
// CODE
}
})()
//somemodul.ctrl.js
(function () {
angular.module('somemodul')
.controller('someModuleCtrl', someModuleCtrl); //add to module
function someModuleCtrl() {
// CODE
}
})()
//somemodul.srv.js
(function () {
angular.module('somemodul')
.service('someModuleSrv', someModuleSrv); //add to module
function someModuleSrv() {
// CODE
}
})();
On build, Gulp do concat and everything works fine.
With ECMA6 We need to import all these modules into app.js. And now I see two options:
1) To concate myself all 'somemodul' files into single file:
//somemodul.js
export default angular.module('somemodul', [])
.directive('someModuleDrv', someModuleDrv)
.service('someModuleSrv', someModuleSrv)
.controller('someModuleCtrl', someModuleCtrl);
function someModuleDrv() { };
function someModuleSrv() { };
function someModuleCtrl() { };
2) Import all submodules into 'somemodule.mdl.js':
//somemodul.mdl.js
import someModuleDrv from './somemodul.drv.js'
import someModuleSrv from './somemodul.srv.js'
import someModuleCtrl from './somemodul.ctrl.js'
export default angular.module('somemodul', [
someModuleDrv.name,
someModuleSrv.name,
someModuleCtrl.name
]);
//somemodul.drv.js
export default angular.module('somemodul.drv', [])
.directive('someModuleDrv', someModuleDrv);
function someModuleDrv() {
// CODE
}
//somemodul.srv.js
export default angular.module('somemodul.srv', [])
.directive('someModuleSrv', someModuleSrv);
function someModuleSrv() {
// CODE
}
//somemodul.ctrl.js
export default angular.module('somemodul.ctrl', [])
.directive('someModuleCtrl', someModuleCtrl);
function someModuleCtrl() {
// CODE
}
Both options works. Unfortunately both options requires a lot of hands-on work. So I'm looking for possible other solution.....
Thanks.