Skip to content

Commit 6a6e771

Browse files
author
QRaimbault
committed
📝 Writing README + eslint vue config
1 parent d5b4868 commit 6a6e771

File tree

12 files changed

+12860
-573
lines changed

12 files changed

+12860
-573
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*.js

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
plugins: ["vue"],
3-
extends: ["plugin:vue/essential", "prettier"],
3+
extends: ["plugin:vue/recommended", "prettier"],
44
rules: {
55
"object-shorthand": "error"
66
}

README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Vue.JS Starter
2+
3+
<p align="center">
4+
<a href="https://vuejs.org" target="_blank" rel="noopener noreferrer">
5+
<img width="100" src="https://vuejs.org/images/logo.png" alt="Vue logo">
6+
</a>
7+
</p>
8+
9+
<p align="center">
10+
<img src="https://img.shields.io/npm/l/vue.svg" alt="License">
11+
</p>
12+
13+
A lightweight Vue.js starter.
14+
15+
## Built-in modules
16+
17+
- [Vue.js 2](https://vuejs.org/)
18+
- [Vue Router 3](https://router.vuejs.org/)
19+
- [Vuex 3](https://vuex.vuejs.org/)
20+
- [Vue Cookie](https://github.com/alfhen/vue-cookie)
21+
- [ES6](http://es6-features.org/) using [Babel](https://babeljs.io/)
22+
- [Webpack 4](https://webpack.js.org/)
23+
- [Axios](https://github.com/axios/axios/)
24+
- [SASS](http://sass-lang.com/)
25+
- [ESLint](http://eslint.org/)
26+
- [SASSLint](https://github.com/sasstools/sass-lint)
27+
28+
You can find documentation and informations about each modules by following the above links.
29+
30+
## Usage
31+
32+
We recommend using Yarn but you can also use NPM.
33+
34+
There is only 3 commands that you can either run using `npm run` or `yarn`:
35+
36+
- `start` to launch a developpement server with hot reload.
37+
- `build` to create a production version in `/dist`.
38+
- `serve` to launch a web server in `/dist`.
39+
40+
## Configuration
41+
42+
Application configuration is located in `src/config.js`.
43+
44+
Build can be configured in `webpack.config.js`, like the dev server host and port.
45+
46+
```json
47+
serve: {
48+
host: "localhost",
49+
port: 3000
50+
}
51+
```
52+
53+
SASS Linter can be configured in `.sass-lint.yml`.
54+
55+
ESLint can be configured in `.eslintrc.js`.
56+
57+
## Routing
58+
59+
Routes are listed in `src/router/index.js` and should contain a meta node with a title, it will be displayed as the document.title, concatened with the separator and the site name in application config.
60+
61+
```json
62+
{
63+
"path": "/",
64+
"name": "Home",
65+
"component": Index,
66+
"meta": {
67+
"title": "Accueil"
68+
}
69+
}
70+
```
71+
72+
## API
73+
74+
API use Axios and the base configuration is set in application configuration file.
75+
76+
```js
77+
export const APIConfig = {
78+
baseURL: "",
79+
withCredentials: true,
80+
crossDomain: true,
81+
contentType: false,
82+
responseType: "json",
83+
headers: {
84+
Accept: "application/json",
85+
"Content-Type": "application/json"
86+
}
87+
};
88+
```
89+
90+
Axios configuration reference is available [here](https://github.com/axios/axios#request-config).
91+
92+
The Axios instance is then generated and exported in `src/helpers/API.js` and you can import it in your views/components this way:
93+
94+
```js
95+
import api from "@API";
96+
```
97+
98+
## Vuex
99+
100+
The Vuex store is located in `src/vuex`.
101+
102+
There is a main config file (`src/vuex/store.js`) and a `modules` directories.
103+
104+
If your application is simple, you can put your state, getters, mutators and actions directly in the store. If it is more complexe, create one sub-directory in `modules` by functionnality and import in in the store.
105+
106+
The store is accessible from any component/view using `this.$store`.
107+
108+
## Style
109+
110+
All your style should be located in the `src/scss` directory.
111+
112+
There is 3 sub-directories:
113+
114+
- `global` for your reset, mixins, variables, functions.
115+
- `views` for your view specific styles.
116+
- `components` for your components specific styles.
117+
118+
You should import styles in the `<script>` tag in each component.
119+
120+
You can also put style in the `<style>` tag in each component, scoped or not, the style injection works the same way using scss files or `<style>` tag.
121+
122+
## Single file component
123+
124+
This starter uses [Single File Components](https://vuejs.org/v2/guide/single-file-components.html) structure, which is more suitable for large project but doesn't make it harder for small apps.
125+
126+
### Views
127+
128+
Views are located in `src/views` and should have their unique styles. It can be compared to a "page". The routes are pointing to views and not to components. They can include one or more components or even none.
129+
130+
### Components
131+
132+
Components are located in `src/components` and should have their unique styles. Components must be imported and used in views. They should be separated in sub-directories organized by views or by functionnalities.
133+
134+
## Webpack Aliases
135+
136+
Webpack allows to put some aliases in the webpack config, so you can have shorter and more friendly import statements in your components/views. By default, this starter comes with some aliases listed bellow:
137+
138+
- `@API` pointing to `src/helpers/API.js`, so directly to the configured Axios instance
139+
- `@Config` pointing to `src/config.js`
140+
- `@Component` pointing to `src/components`
141+
- `@ComponentStyle` pointing to `src/scss/components`
142+
- `@View` pointing to `src/views`
143+
- `@ViewStyle` pointing to `src/scss/views`
144+
145+
An example usage of these aliases is to get the API helper from a view/component:
146+
147+
```js
148+
import api from "@API";
149+
```
150+
151+
Or to get a component from a view:
152+
153+
```js
154+
import Articles from "@Component/Index/Articles.vue";
155+
```
156+
157+
## License
158+
159+
All the content is under [MIT license](https://github.com/QRaimbault/vue-js-starter-scss/blob/master/LICENSE).

bin/spa-server.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const express = require('express');
2-
const path = require('path');
1+
const express = require("express");
2+
const path = require("path");
33

4-
const openBrowser = require('./lib/open-browser');
4+
const openBrowser = require("./lib/open-browser");
55

66
const app = express();
7-
const publicPath = path.join(process.cwd(), 'dist');
8-
const port = 5000;
7+
const publicPath = path.join(process.cwd(), "dist");
8+
const port = 3001;
99

10-
app.use('/', express.static(publicPath, { index: false }));
11-
app.get('/*', (request, response) => {
10+
app.use("/", express.static(publicPath, { index: false }));
11+
app.get("/*", (request, response) => {
1212
response.sendFile(`${publicPath}/index.html`);
1313
});
1414

1515
app.listen(port);
1616

1717
// eslint-disable-next-line no-console
18-
console.log('Server started!');
18+
console.log("Server started!");
1919
// eslint-disable-next-line no-console
2020
console.log(`http://localhost:${port}`);
2121

0 commit comments

Comments
 (0)