This is a demo project to just show how we are trying to build frontend application with vue 2 and typescript. It uses a set of tools as well as methodologies and conventions which help us to build well-designed and maintanable code.
- Vue Class Component itself https://github.com/vuejs/vue-class-component
- Vue property decorator https://github.com/kaorun343/vue-property-decorator
- Vuex Class https://github.com/ktsn/vuex-class
- Only scoped styles in components. However one global not-scoped style is allowed for really global things. Can be in App component, for example.
- Directory @types for types https://www.typescriptlang.org/tsconfig#types
- Default slots (while you can)
- Use facades
- Relative imports inside modules, absolute - outside modules or to the core
-
Use public interfaces (known also as "facades") for every module. (index.ts or index.js file) This serves a lot of purposes. Some of them:
- Manage complexity of code. To use a module, you need to understand only pubic interface and not entire module.
- Facade defines how to use a module
- It can serve well for backward compatibility: you only need to preserve the public interface
- Facades give an opportunity to control modules connections
-
Different ways of using modules:
- Direct imports through facades
- Event dispatcher https://www.digitalocean.com/community/tutorials/vuejs-global-event-bus
- Dom modifications
-
Useful conventions:
- Absolute (@) intermodules and core imports
- Relative imports (./, ../, etc) inside module itself
-
Diagnostic
yarn depcruise-modules
(and webpack workaround)
- Enforcement
- eslint
Checks for restriction:yarn lint
'no-restricted-imports': ['error', { patterns: ['**/modules/*/*'] }]
- dependency-cruiser
depcruise-lint
yarn install
yarn serve