Run Vue3 Project
Vue3 project init
- Ensure Node.js version >= 16.0;
- Command-line
npm init vue@latest
to install vue.
- [✔] add Typscript
- [✔] add Vue Router
- [✔] add Pinia (state management)
- [✔] add ESLint (code vertify)
- [✔] add Prettier (code formatting)
- Add
scss
1
npm add -D sass
- Run Project
1
2
3cd [your-project-name]
npm install
npm run dev
Analyze Dirctory File
vite.config.js
Every time you run
npm run dev
, Vite will analyze this dirctory.
You can config Package、Local service and more.
1 |
|
- Other Dirctory
:file assets: static file, like images, css;
:file components: public components;
:file stores: Pinia state management;
:file router: Vue Router file;
:file views: vue pages;
:file public: file which will not be packaged, like icon;
build project
1 |
|
npm run dev
|npx vite
Run local service, and provide Hot Module Replacement (HMR热更新)
npm run build
|npx vite build
Build file to :file
dist
npm run preview
|npx vite preview --port 4173
Run local service and preview the project in :file
dist
why to build
- Syntax compilation(语法编译)
- Trans
.vue
file tojs
andcss
ES6
toES5
- File compression(文件压缩)
- Reduce HTTP Requests
- Code compression
- Remove space、annotate(注释),Change name of variable、function
- Use the plugin only have used
- Splice file from
node_moudle
to build file
Options API vs Composition API
Options API
According to different characteristics, split to different option, like data, method, computed, life cycle
Composition API
With
<script set>
, you can write code like original javascript;
According to ‘function’ to distinguish(区分) code area and It can improve readability;
Usereactive()
andref()
to add relative.
本文作者: 孟 虎
本文链接: https://menghu1994.github.io/blog/2023/10/Vue/start/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!