Skip to content

Commit a39c99c

Browse files
committed
feat(playground): playground base
1 parent 444ad9d commit a39c99c

18 files changed

+450
-0
lines changed

playground/.eslintrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-env node */
2+
require('@rushstack/eslint-patch/modern-module-resolution')
3+
4+
module.exports = {
5+
root: true,
6+
'extends': [
7+
'plugin:vue/vue3-essential',
8+
'eslint:recommended',
9+
'@vue/eslint-config-typescript',
10+
'@vue/eslint-config-prettier/skip-formatting'
11+
],
12+
parserOptions: {
13+
ecmaVersion: 'latest'
14+
}
15+
}

playground/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
auto-components.d.ts
31+
auto-imports.d.ts

playground/.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"printWidth": 100,
7+
"trailingComma": "none"
8+
}

playground/.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3+
}

playground/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# playground
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](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).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
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.
12+
13+
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:
14+
15+
1. Disable the built-in TypeScript Extension
16+
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
17+
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
18+
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
19+
20+
## Customize configuration
21+
22+
See [Vite Configuration Reference](https://vitejs.dev/config/).
23+
24+
## Project Setup
25+
26+
```sh
27+
pnpm install
28+
```
29+
30+
### Compile and Hot-Reload for Development
31+
32+
```sh
33+
pnpm dev
34+
```
35+
36+
### Type-Check, Compile and Minify for Production
37+
38+
```sh
39+
pnpm build
40+
```
41+
42+
### Lint with [ESLint](https://eslint.org/)
43+
44+
```sh
45+
pnpm lint
46+
```

playground/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

playground/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

playground/package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "playground",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "run-p type-check build-only",
8+
"preview": "vite preview",
9+
"build-only": "vite build",
10+
"type-check": "vue-tsc --noEmit",
11+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
12+
"format": "prettier --write src/"
13+
},
14+
"dependencies": {
15+
"@swc/wasm-web": "^1.3.37",
16+
"@unocss/reset": "^0.50.3",
17+
"@varlet/touch-emulator": "^2.8.5",
18+
"@varlet/ui": "^2.8.5",
19+
"vue": "^3.2.47"
20+
},
21+
"devDependencies": {
22+
"@rushstack/eslint-patch": "^1.2.0",
23+
"@types/node": "^18.14.2",
24+
"@vitejs/plugin-vue": "^4.0.0",
25+
"@vitejs/plugin-vue-jsx": "^3.0.0",
26+
"@vue/eslint-config-prettier": "^7.1.0",
27+
"@vue/eslint-config-typescript": "^11.0.2",
28+
"@vue/tsconfig": "^0.1.3",
29+
"eslint": "^8.34.0",
30+
"eslint-plugin-vue": "^9.9.0",
31+
"npm-run-all": "^4.1.5",
32+
"prettier": "^2.8.4",
33+
"typescript": "~4.8.4",
34+
"unocss": "^0.50.3",
35+
"unplugin-auto-import": "^0.15.0",
36+
"unplugin-vue-components": "^0.24.0",
37+
"vite": "^4.1.4",
38+
"vite-plugin-static-copy": "^0.13.1",
39+
"vue-tsc": "^1.2.0"
40+
}
41+
}

playground/public/favicon.ico

4.19 KB
Binary file not shown.

playground/src/App.vue

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<script setup lang="ts">
2+
import { transformScript, FileType } from '../../src/index'
3+
import initSwc, { parseSync } from '@swc/wasm-web'
4+
5+
const count = ref(0)
6+
7+
const text = ref('')
8+
9+
async function init() {
10+
await initSwc()
11+
12+
const code = transformScript({
13+
fileType: FileType.ts,
14+
script: `
15+
import { defineComponent, PropType, ref } from "vue"
16+
import Header from "../components/Header.vue"
17+
import Tab from "../components/Tab.vue"
18+
import touchdir from "vtouchdir"
19+
export default defineComponent({
20+
name: 'App',
21+
components: {
22+
Header,
23+
Tab,
24+
},
25+
directives: {
26+
force: {},
27+
touchdir,
28+
},
29+
props: {
30+
items: Array as PropType<number[]>
31+
},
32+
emit: ["click"],
33+
setup(props, { emit, attrs, slots: mySlots, expose }) {
34+
const bar = ref(0)
35+
expose({ bar })
36+
emit("change");
37+
return {
38+
bar
39+
}
40+
}
41+
})`.trim(),
42+
offset: 0,
43+
parseSync: parseSync as any,
44+
output: {
45+
warn() {
46+
47+
},
48+
log() {
49+
50+
},
51+
success() {
52+
53+
},
54+
error() {
55+
}
56+
}
57+
})
58+
59+
if (code) {
60+
text.value = code
61+
}
62+
}
63+
64+
init()
65+
</script>
66+
67+
<template>
68+
<div>
69+
<div>
70+
{{ count }}
71+
<var-button @click="count++" type="primary">click</var-button>
72+
</div>
73+
<var-paper :elevation="2">
74+
<pre>
75+
{{ text }}
76+
</pre>
77+
</var-paper>
78+
</div>
79+
</template>
80+
81+
<style>
82+
html,
83+
body,
84+
#app {
85+
height: 100%;
86+
width: 100%;
87+
}
88+
</style>
89+

playground/src/assets/base.css

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* color palette from <https://github.com/vuejs/theme> */
2+
:root {
3+
--vt-c-white: #ffffff;
4+
--vt-c-white-soft: #f8f8f8;
5+
--vt-c-white-mute: #f2f2f2;
6+
7+
--vt-c-black: #181818;
8+
--vt-c-black-soft: #222222;
9+
--vt-c-black-mute: #282828;
10+
11+
--vt-c-indigo: #2c3e50;
12+
13+
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
14+
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
15+
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
16+
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
17+
18+
--vt-c-text-light-1: var(--vt-c-indigo);
19+
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
20+
--vt-c-text-dark-1: var(--vt-c-white);
21+
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
22+
}
23+
24+
/* semantic color variables for this project */
25+
:root {
26+
--color-background: var(--vt-c-white);
27+
--color-background-soft: var(--vt-c-white-soft);
28+
--color-background-mute: var(--vt-c-white-mute);
29+
30+
--color-border: var(--vt-c-divider-light-2);
31+
--color-border-hover: var(--vt-c-divider-light-1);
32+
33+
--color-heading: var(--vt-c-text-light-1);
34+
--color-text: var(--vt-c-text-light-1);
35+
36+
--section-gap: 160px;
37+
}
38+
39+
@media (prefers-color-scheme: dark) {
40+
:root {
41+
--color-background: var(--vt-c-black);
42+
--color-background-soft: var(--vt-c-black-soft);
43+
--color-background-mute: var(--vt-c-black-mute);
44+
45+
--color-border: var(--vt-c-divider-dark-2);
46+
--color-border-hover: var(--vt-c-divider-dark-1);
47+
48+
--color-heading: var(--vt-c-text-dark-1);
49+
--color-text: var(--vt-c-text-dark-2);
50+
}
51+
}
52+
53+
*,
54+
*::before,
55+
*::after {
56+
box-sizing: border-box;
57+
margin: 0;
58+
position: relative;
59+
font-weight: normal;
60+
}
61+
62+
body {
63+
min-height: 100vh;
64+
color: var(--color-text);
65+
background: var(--color-background);
66+
transition: color 0.5s, background-color 0.5s;
67+
line-height: 1.6;
68+
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
69+
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
70+
font-size: 15px;
71+
text-rendering: optimizeLegibility;
72+
-webkit-font-smoothing: antialiased;
73+
-moz-osx-font-smoothing: grayscale;
74+
}

playground/src/assets/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

playground/src/assets/main.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@import './base.css';
2+
3+
#app {
4+
max-width: 1280px;
5+
margin: 0 auto;
6+
padding: 2rem;
7+
8+
font-weight: normal;
9+
}
10+
11+
a,
12+
.green {
13+
text-decoration: none;
14+
color: hsla(160, 100%, 37%, 1);
15+
transition: 0.4s;
16+
}
17+
18+
@media (hover: hover) {
19+
a:hover {
20+
background-color: hsla(160, 100%, 37%, 0.2);
21+
}
22+
}
23+
24+
@media (min-width: 1024px) {
25+
body {
26+
display: flex;
27+
place-items: center;
28+
}
29+
30+
#app {
31+
display: grid;
32+
grid-template-columns: 1fr 1fr;
33+
padding: 0 2rem;
34+
}
35+
}

playground/src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createApp } from "vue";
2+
import App from "./App.vue";
3+
4+
import "uno.css";
5+
import "@unocss/reset/eric-meyer.css";
6+
7+
import "@varlet/touch-emulator";
8+
9+
createApp(App).mount("#app");

playground/src/shims.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module '*.vue' {
2+
import { type DefineComponent } from 'vue'
3+
const component: DefineComponent<{}, {}, any>
4+
export default component
5+
}
6+

0 commit comments

Comments
 (0)