It is quite opinionated, so feel free - to make suggestions to improve it.
Includes following:
- Webpack (modules, assets bundling)
- babel (modern javascript features)
- babel-plugin-angularjs-annotate
- karma test runner configuration with code coverage reports
- node-sass for styles + AutoPrefixer
Requirements:
- NodeJS 8+ is required.
- Yarn is optional to use, but I recommend using it. (if no - npm is ok).
- Install dependencies
yarn install
- Start dev server
yarn run dev
open http://localhost:2992 - Lint your code
yarn run lint
- Run unit tests
yarn run test
- Create build for deployment
yarn run build
for production build, oryarn run build-dev
for development build
To analyze your bundle size - I recommend using Webpack Bundle Analyzer
At first be sure that you are familiar with ES2015, some useful materials:
- tutorial from BabelJS
- Exploring ES6: Upgrade to the next version of JavaScript by Dr. Axel Rauschmayer
Read Airbnb JavaScript Style Guide - it is important to know, what is good and what is not, and why.
At least briefly read webpack documentation it is crucial to understand how it works in general.
├── build # build stats
├── public # public folder (webroot for dev server)
│ ├── _assets # build results - assets packed by webpack
│ └── index.html # one of app entry points, for dev server
└── src # app sources
├── demo # one of app modules
├── index.js # app entry module
├── index.scss #
└── index.test.js # entry point for test karma
Except my notes below(which can be incomplete and outdated), I highly encourage you to check out:
Application organisation rules:
- Split app into angular "modules"
- every module should have own folder, and should be defined in one file which will require all module components and will export module name
- module can have nested modules
- module can require other modules which are direct siblings of it or parent modules, or modules nested in it (if you need to require module that is nested in "sibling" - you you should move it up by hierarchy before requiring it)
- Keep modules small - if module is too big, maybe it should be few modules
- Every file should have only one entity inside it, for example if there is directive which has controller and template - there should be three files, plus likely two for unit tests
- Group related resources by folders
- Name files with suffixes
Directive
,Controller
,Factory
,Service
,Provider
- Use
.test
suffix for test file names
- Prefer to use isolated scopes
- Use controllerAs syntax
- Controller should act as ViewModel, use $scope only if you need it
- All model layer (data fetching, business logic) should be in services