Skip to content

Commit

Permalink
Merge pull request #105 from Ubugeeei/104-playground-improve
Browse files Browse the repository at this point in the history
other: #104 🔹 create vue playground
  • Loading branch information
Ubugeeei committed Aug 14, 2023
2 parents 3e433bb + 1b2e071 commit 16b1b37
Show file tree
Hide file tree
Showing 14 changed files with 765 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ $ pnpm run dev:setup
$ pnpm run dev
```

original vue.js 3.3 playground

```sh
$ pnpm run vue:setup
$ pnpm run vue:dev
```

```
# ⚠️ status
This online book is currently a work in progress.
Expand Down Expand Up @@ -157,3 +166,4 @@ Please refer to the information below for the progress status.
| router | ✅ | |
| keep-alive | | |
| suspense | | |
```
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"setup": "pnpm i && ts-node --esm tools/create-chibivue/main.ts",
"dev": "cd example/playground && pnpm i && pnpm run dev",
"dev:setup": "ts-node --esm tools/chibivue-playground/main.ts",
"vue": "cd example/vue && pnpm i && pnpm run dev",
"vue:setup": "ts-node --esm tools/vue-playground/main.ts",
"dev:app": "cd example/app && pnpm i && pnpm run dev",
"test": "vitest",
"prepare": "husky install",
Expand Down
40 changes: 40 additions & 0 deletions tools/vue-playground/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fs from "fs";
import fse from "fs-extra";

const red = (s: string) => `\x1b[31m${s}\x1b[0m`;
const green = (s: string) => `\x1b[32m${s}\x1b[0m`;
const blue = (s: string) => `\x1b[34m${s}\x1b[0m`;

const targetDirPath = "example/vue";

// check if target path is empty
if (!targetDirPath) {
console.log("Please specify the target path!");
process.exit(1);
}

// check if target path exists. auto create if not
if (fs.existsSync(targetDirPath)) {
const files = fs.readdirSync(targetDirPath);
if (files.length) {
console.log("");
console.log(`${red("Oops!")} Target directory is not empty!`);
console.log("");
process.exit(1);
}
} else {
fs.mkdirSync(targetDirPath, { recursive: true });
}

// copy template files
const templateDirPath = `tools/vue-playground/template`;
fse.copySync(templateDirPath, targetDirPath);

// message
console.log("");
console.log("----------------------------------------------------------");
console.log(
`${green("chibivue project created!")} ${blue(">>>")} ${targetDirPath}`
);
console.log(`Enjoy your learning! 😎`);
console.log("----------------------------------------------------------");
24 changes: 24 additions & 0 deletions tools/vue-playground/template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
18 changes: 18 additions & 0 deletions tools/vue-playground/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support For `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
13 changes: 13 additions & 0 deletions tools/vue-playground/template/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions tools/vue-playground/template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "vue",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.1.0",
"typescript": "^4.9.3",
"vite": "^4.2.0",
"vue-tsc": "^1.2.0"
}
}
Loading

0 comments on commit 16b1b37

Please sign in to comment.