Handling controllers and services in subfolders
SoldierCorp opened this issue · 6 comments
Hi!
In order to use this kind of app structure for angular
app.js
--- controllers
------ controller.js
--- services
------ service.js
The webpack configuration you have will work? Or if not, is there a way you can help me to do that?
Kind regards.
Hi @SoldierCorp
This is something I've done in some of my projects, but it requires the use of require() instead of ES6 import.
requireAll(require.context('./services', true, /\.js$/));
function requireAll(require) {
require.keys().forEach(require);
}What the above code does is it recursively looks through the directory "services" for all files ending with ".js" and require() it.
EDIT: I fixed the error I posted originally but I am still have problems.
I tried following the example by stefek99, but some information must be missing. I created a folder under app called "spanText" and added a js file. I then referenced it in app.js. My js file is a copy of the app.js file in the git repository. I renamed app to spanText and the directive to . I copied the html template etc.... However, my custom directive is never getting rendered. Its an empty tag in the dom.
What is missing?
here is a bigger project that I just needed to upgrade to unit tests and used the great config from this repo. Thanks!
https://github.com/berzerk-interactive/angular-1.6.x-webpack-components-material-es6
@surfjedi maybe you can help me fill in the blanks. when I run the code from the github repo you posted, all I see in browser is a directory listing of the generated js files. I do not see any of the "angular stuff" kicking in at all, definitely not seeing what is designed in index.html

@tatmanblue that is what you should see.
I fixed a missing dep in package.json earlier today. Sorry - pull again. Then make sure you "npm install" then "npm run dev".
there is minor bug in lazy loaded states due to code splitting im working on, and I'm adding tests FYI. Its a work in progress. But the folder structure you are looking is there and working
