I am curious about the common practices and consensus among the Angular2 community when it comes to writing reusable code in TypeScript. I have gathered some information and questions related to Angular2 that I would like to discuss.
Organizing Module/App Structure and File Naming
In the official tutorial, all code is placed in the
app
directory, while dependencies likenode_modules
or typings are kept in the parent directory.Using lowercase file names,
.component.ts
extension for components, and.service.ts
for services. Is putting all files in the same directory going to create a messy structure?Following the guideline of having one class/interface/enum per file. Should naming conventions be based on the Microsoft TypeScript Coding guidelines for consistency?
Bundle Modules
- Is it recommended for modules to compile and bundle themselves using the
postinstall
npm
hook? Or is it better to directly provide a bundled version on git similar to JavaScript libraries? - When expecting a module to be used only by the browser, is it preferable to utilize the
system
type of modules by default, or should one always opt for UMD? - Are there specific advantages to using CommonJS or AMD over
system
?
Integration of 3rd Party Modules
- Should one assume that other developers will embed the modules with
<script>
tags or load them usingSystem.import()
? - If the modules have dependencies on other JavaScript libraries, is it more efficient to provide a bundled version with all dependencies included or just define them in the
package.json
file?