Fix `grunt dist` under Bower by separating docs into separate task

Also does some refactoring. Fixes #13949.
CC: @twbs/team