can grunt automatically include all my js in index.html? [closed]
Asked Answered
A

2

9

I'm new to grunt. I'm coming from rails and getting into angular. From what I can see grunt usemin can replace <script src=...> between build directives and replace that with a single minified js during grunt build. That's great for deployment.

However whenever I add new angular controllers during development, I also have to remember to add them to my index.html. That's a hassle, and the same goes for if I move my feature folders around, I have to change all my src paths in index.html.

It would be nice if in development, grunt would watch all my src/**/*.js and automatically add them all to index.html for me... similar to rails asset pipeline and asset manifest that just does require_tree when you're developing. You can put files anywhere and it's automatically available.

Is there such an existing solution or example for a grunt watcher? Thanks

Atony answered 2/11, 2013 at 0:20 Comment(2)
That would be amazing. I have the same issue you do, whenever i add a new controller or anything, i have to insert the code into my index.html file. +1 to Question.Gav
Watching the files for a change is simple enough in grunt, but it would be a little harder to insert them into the html because sometimes insertion order does matter. Someone may have to come up with unique comment syntax (similiar to the minified one) which could distinguish what types of files go where.Unparalleled
B
5

Have a look at https://github.com/jwvdiermen/grunt-include-source#usage-examples

Works for both including JS and CSS.

Bovid answered 14/11, 2013 at 12:3 Comment(0)
C
1

if you use use bower to manage your assets, grunt-bower-install is what you looking for. otherwise you can use grunt-bower-requirejs-alias. for rails-like require_tree, you can try node-require-dir. why not search in npm registry ? it's a good place to find plugins.

Cabanatuan answered 2/11, 2013 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.