├── .babelrc
├── .gitattributes
├── .gitignore
├── .vscode
└── settings.json
├── LICENSE
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── src
├── @types
│ ├── jsx.d.ts
│ └── vue-shims.d.ts
├── assets
│ ├── icons
│ │ └── favicon.ico
│ └── images
│ │ └── logo-vue.png
├── components
│ ├── app
│ │ └── app.vue
│ └── hello-word
│ │ ├── hello-word-extend.vue
│ │ ├── hello-word-tsx.scss
│ │ ├── hello-word-tsx.tsx
│ │ └── hello-word.vue
├── index.scss
├── index.ts
└── store
│ ├── hello
│ ├── hello.ts
│ └── index.ts
│ ├── index.ts
│ ├── state-types.ts
│ └── store.ts
├── tsconfig.json
├── webpack.config.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false
5 | }],
6 | "stage-2"
7 | ],
8 | "plugins": [
9 | "transform-runtime",
10 | "transform-vue-jsx"
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/**/*.js
3 | src/**/*.css
4 | dist
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.associations": {
4 | "*.vue": "vue"
5 | },
6 | "tslint.autoFixOnSave": true
7 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Israel Zablianov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vue Vuex TypeScript Webpack seed
2 |
3 | This seed project includes some of the 'hot' and latests web technologies such as [TypeScript](https://www.typescriptlang.org/), [Vue](https://vuejs.org), [Vuex](https://vuex.vuejs.org/en/),[Vuex-Typescript](https://github.com/istrib/vuex-typescript), [Webpack](https://webpack.js.org/), [SASS](https://sass-lang.com/) and more, all working together beautifully.
4 |
5 | This project is simple enough to understand with examples for every needed part e.g. hello component with typescript and property decorators, hello store with `Vuex` and `Vuex-Typescript` and render function with tsx support.
6 |
7 | # Getting Started
8 |
9 | Let's run some commands.
10 |
11 | ```sh
12 | npm install // or yarn install
13 | npm run build
14 | npm start
15 | ```
16 |
17 | In this point you should have zero errors (otherwise, please open an issue or contact me for help) and you can start coding.
18 |
19 |
20 | For readable and maintainable code, please save the following structure:
21 | ```txt
22 | src/
23 | ├─ components/
24 | | └─ specificComponentFolder
25 | └─ store/
26 | └─ specificModuleStateFolder/
27 | ```
28 |
29 | The project is configured with webpack, and webpack-dev-server with hot reloading.
30 | So all you need to do is save the changes and the page will refresh automatically.
31 |
32 |
33 | # Using decorators to define a component
34 |
35 | This seed project contains example of components, defined using [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html), [vue-class-component](https://github.com/vuejs/vue-class-component) and [vue-property-decorator](https://github.com/kaorun343/vue-property-decorator).
36 |
37 |
38 | ```ts
39 | import { Vue, Component, Prop } from "vue-property-decorator";
40 |
41 | @Component()
42 | export default class HelloDecorator extends Vue {
43 |
44 | @Prop(type: String, default: "")
45 | name: string;
46 |
47 | @Prop({ type: Number, default: 1 })
48 | initialEnthusiasm: number;
49 |
50 | enthusiasm = this.initialEnthusiasm;
51 |
52 | increment() {
53 | this.enthusiasm++;
54 | }
55 |
56 | decrement() {
57 | this.enthusiasm--;
58 | }
59 |
60 | get exclamationMarks(): string {
61 | return Array(this.enthusiasm + 1).join('!');
62 | }
63 | }
64 | ```
65 |
66 | Instead of using `Vue.extend` to define our component, we create a class extending `Vue` and decorate it using the `@Component` decorator from the `vue-class-component` package (which was re-exported from the `vue-property-decorator` package).
67 |
68 | Properties are defined by prefixing instance variables with the `@Prop()` decorator from the `vue-property-decorator` package.
69 |
70 | Regular instance variables, such as `enthusiasm` in our example, are automatically made available for data binding to the template, just as if they had been defined in the `data` field.
71 | Note that all variables must be set to a value other than `undefined` for the binding to work.
72 |
73 | Similarly, methods such as `increment` are treated as if they had been written in the `methods` field, and are automatically made available for the template.
74 |
75 | Finally, computed properties like `exclamationMarks` are simply written as `get` accessors.
76 |
77 | # Using render functions & tsx to define a component
78 |
79 | Vue also supports [render functions & jsx/tsx](https://vuejs.org/v2/guide/render-function.html).
80 | If you are familiar with [React](https://reactjs.org/) you probably know how great it is.
81 |
82 | ```tsx
83 | import { Vue, Component, Prop } from "vue-property-decorator";
84 | import { CreateElement, VNode } from "vue/types";
85 | import "./hello-word-tsx.scss";
86 |
87 | @Component({
88 | })
89 | export default class HelloWord extends Vue {
90 |
91 | @Prop({ type: String, default: "" })
92 | name: string;
93 |
94 | @Prop({ type: Number, default: 1 })
95 | enthusiasmLevel: number;
96 |
97 | public get helloMessage(): string {
98 | return "Hello " + this.name + this.getExclamationMarks(this.enthusiasmLevel);
99 | }
100 |
101 | public getExclamationMarks(numChars: number): string {
102 | return Array(numChars + 1).join('!');
103 | }
104 |
105 | public onDecrement() {
106 | this.$emit("onDecrement");
107 | }
108 |
109 | public onIncrement() {
110 | this.$emit("onIncrement");
111 | }
112 |
113 | public render(h: CreateElement): VNode {
114 | return (
115 |
116 |
117 | {this.helloMessage}
118 |
119 |
120 |
121 |
122 |
123 |
124 | );
125 | }
126 | }
127 | ```
128 | As you can see, this is no longer a single file with template, style and script.
129 | The render function is alternative to templates and the style is imported from another file.
130 | Sometimes it is mandatory to use tsx elements so in this seed project you have the ability
131 | to use both, tsx files and vue files.
132 |
133 | This seed project is based on Microsoft-TypeScript-Vue-Starter
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vue-vuex-typescript-webpack-seed
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-vuex-typescript-webpack-seed",
3 | "version": "1.0.0",
4 | "private": true,
5 | "description": "An actual working seed of vue, vuex, typescript and webpack",
6 | "main": "index.html",
7 | "scripts": {
8 | "build": "webpack",
9 | "test": "echo \"Error: no test specified\" && exit 1",
10 | "start": "webpack-dev-server"
11 | },
12 | "keywords": [],
13 | "author": {
14 | "name": "Israel Zablianov",
15 | "url": "https://github.com/IsraelZablianov/vue-vuex-typescript-webpack-seed"
16 | },
17 | "license": "MIT",
18 | "dependencies": {
19 | "vue": "^2.5.2",
20 | "vuex": "^3.0.1",
21 | "vue-property-decorator": "^6.0.0",
22 | "vuex-typescript": "^3.0.2"
23 | },
24 | "devDependencies": {
25 | "@types/node": "^9.4.6",
26 | "awesome-typescript-loader": "^3.0.0",
27 | "babel-core": "^6.22.1",
28 | "babel-helper-vue-jsx-merge-props": "2.0.0",
29 | "babel-loader": "^7.1.1",
30 | "babel-plugin-syntax-jsx": "^6.18.0",
31 | "babel-plugin-transform-runtime": "^6.22.0",
32 | "babel-plugin-transform-vue-jsx": "^3.5.0",
33 | "babel-preset-env": "^1.3.2",
34 | "babel-preset-stage-2": "^6.22.0",
35 | "babel-register": "^6.22.0",
36 | "copy-webpack-plugin": "^4.5.0",
37 | "css-loader": "^0.28.10",
38 | "file-loader": "^1.1.11",
39 | "node-sass": "^4.7.2",
40 | "prettier": "1.12.1",
41 | "sass-loader": "^6.0.7",
42 | "style-loader": "^0.20.2",
43 | "ts-loader": "^3.5.0",
44 | "typescript": "2.6.1",
45 | "url-loader": "^1.0.1",
46 | "vue-class-component": "^6.0.0",
47 | "vue-loader": "^13.3.0",
48 | "vue-template-compiler": "^2.5.2",
49 | "webpack": "^3.6.0",
50 | "webpack-dev-server": "^2.11.1"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/@types/jsx.d.ts:
--------------------------------------------------------------------------------
1 | import Vue, { VNode } from "vue"
2 |
3 | declare global {
4 | namespace JSX {
5 | interface Element extends VNode {}
6 | interface ElementClass extends Vue {}
7 | interface IntrinsicElements {
8 | [elem: string]: any
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/@types/vue-shims.d.ts:
--------------------------------------------------------------------------------
1 | declare module "*.vue" {
2 | import Vue from "vue";
3 | export default Vue;
4 | }
--------------------------------------------------------------------------------
/src/assets/icons/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IsraelZablianov/vue-vuex-typescript-webpack-seed/140ed457e750d4897049ccd4b5ecf0ab0cc56a4a/src/assets/icons/favicon.ico
--------------------------------------------------------------------------------
/src/assets/images/logo-vue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IsraelZablianov/vue-vuex-typescript-webpack-seed/140ed457e750d4897049ccd4b5ecf0ab0cc56a4a/src/assets/images/logo-vue.png
--------------------------------------------------------------------------------
/src/components/app/app.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Welcome to Vue
6 |
7 |
8 | To get started, edit
9 | src/components/app/app.vue and save to reload.
10 |