Β§2023-08-09

-Vue.js QuickStart

-γ€€θ©¦ι¨“ζ©Ÿε™¨οΌš x8664Arch.yushei.com.tw, /opt/xfs/vue-proj

 node --version
v20.4.0
[alexlai@x8664Arch vue-proj]$ which node
/usr/bin/node
[alexlai@x8664Arch vue-proj]$ which npm
/usr/bin/npm
[alexlai@x8664Arch vue-proj]$ npm --version
9.8.1
$ npm create vue@latest
Need to install the following packages:
create-vue@3.7.2
Ok to proceed? (y) y

Vue.js - The Progressive JavaScript Framework

βœ” Project name: … quickStart
βœ” Package name: … quickstart
βœ” Add TypeScript? … No / Yes
βœ” Add JSX Support? … No / Yes
βœ” Add Vue Router for Single Page Application development? … No / Yes
βœ” Add Pinia for state management? … No / Yes
βœ” Add Vitest for Unit Testing? … No / Yes
βœ” Add an End-to-End Testing Solution? β€Ί No
βœ” Add ESLint for code quality? … No / Yes

Scaffolding project in /opt/xfs/vue-proj/quickStart...

Done. Now run:

  cd quickStart
  npm install
  npm run dev
$ tree quickStart/
quickStart/
β”œβ”€β”€ index.html
β”œβ”€β”€ package.json
β”œβ”€β”€ public
β”‚Β Β  └── favicon.ico
β”œβ”€β”€ README.md
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ App.vue
β”‚Β Β  β”œβ”€β”€ assets
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ base.css
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ logo.svg
β”‚Β Β  β”‚Β Β  └── main.css
β”‚Β Β  β”œβ”€β”€ components
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ HelloWorld.vue
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ icons
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ IconCommunity.vue
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ IconDocumentation.vue
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ IconEcosystem.vue
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ IconSupport.vue
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── IconTooling.vue
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ TheWelcome.vue
β”‚Β Β  β”‚Β Β  └── WelcomeItem.vue
β”‚Β Β  └── main.js
└── vite.config.js

6 directories, 18 files

  1. cd quickStart
$ npm install
$ npm run dev

VITE v4.4.9  ready in 1298 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

Shortcuts
  press r to restart the server
  press u to show server url
  press o to open in browser
  press c to clear console
  press q to quit
  • http://localhost:5173

vue-5173.png

Note that the example components in the generated project are written using the Composition API and , rather than the Options API.

In simple terms, the Options API is like using predefined sections to write your component, while the Composition API is like assembling smaller, reusable functions to build your component's behavior in a more flexible way. Both approaches have their merits, and you can choose the one that fits your project and coding style best.

  1. When you are ready to ship your app to production, run the following:
$ npm run build

> quickstart@0.0.0 build
> vite build

vite v4.4.9 building for production...
βœ“ 23 modules transformed.
dist/assets/logo-277e0e97.svg    0.28 kB β”‚ gzip:  0.20 kB
dist/index.html                  0.42 kB β”‚ gzip:  0.28 kB
dist/assets/index-ef4f98ff.css   3.69 kB β”‚ gzip:  1.19 kB
dist/assets/index-393e57c5.js   60.05 kB β”‚ gzip: 23.86 kB
βœ“ built in 3.96s

$ tree dist
dist
β”œβ”€β”€ assets
β”‚Β Β  β”œβ”€β”€ index-393e57c5.js
β”‚Β Β  β”œβ”€β”€ index-ef4f98ff.css
β”‚Β Β  └── logo-277e0e97.svg
β”œβ”€β”€ favicon.ico
└── index.html

  1. how to serve contents in ~/dist
$ sudo npm install -g serve
$ which serve
/usr/bin/serve
$ cd dist/
$ serve

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                                           β”‚
   β”‚   Serving!                                β”‚
   β”‚                                           β”‚
   β”‚   - Local:    http://localhost:3000       β”‚
   β”‚   - Network:  http://192.168.2.132:3000   β”‚
   β”‚                                           β”‚
   β”‚   Copied local address to clipboard!      β”‚
   β”‚                                           β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • http://localhost:3000

vue-5173.png

Here are some additional tips:
Return to Top