Skip to content

Commit

Permalink
feat: support for vue templates
Browse files Browse the repository at this point in the history
  • Loading branch information
loosheng committed Apr 9, 2021
1 parent d42a806 commit c84fab6
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ const {
lightRed,
red,
stripColors,
blue,
} = require("kolorist");

const cwd = process.cwd();

const TEMPLATES = [yellow("cesium"), green("cesium-ts")];
const TEMPLATES = [
blue("cesium"),
blue("cesium-ts"),
green("cesium-vue"),
green("cesium-vue-ts"),
];

const renameFiles = {
_gitignore: ".gitignore",
Expand Down
27 changes: 27 additions & 0 deletions template-cesium-vue-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Vue 3 + Typescript + Vite

This template should help get you started developing with Vue 3 and Typescript in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings!

### If Using `<script setup>`

[`<script setup>`](https://github.com/vuejs/rfcs/pull/227) is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) instead of Vetur (and disable Vetur).

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

Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can use the following:

### If Using Volar

Run `Volar: Switch TS Plugin on/off` from VSCode command palette.

### If Using Vetur

1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json`
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript
3. Open `src/main.ts` in VSCode
4. Open the VSCode command palette
5. Search and run "Select TypeScript version" -> "Use workspace version"
5 changes: 5 additions & 0 deletions template-cesium-vue-ts/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
13 changes: 13 additions & 0 deletions template-cesium-vue-ts/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" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions template-cesium-vue-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "vite-vue-typescript-starter",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview"
},
"dependencies": {
"cesium": "^1.80.0",
"vue": "^3.0.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.2.1",
"@vue/compiler-sfc": "^3.0.5",
"typescript": "^4.1.3",
"vite": "^2.1.5",
"vite-plugin-cesium": "^1.2.1",
"vue-tsc": "^0.0.15"
}
}
Binary file added template-cesium-vue-ts/public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions template-cesium-vue-ts/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<img class="logo" alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite + Cesium" />
</template>

<script lang="ts">
import { defineComponent } from "vue";
import HelloWorld from "./components/HelloWorld.vue";
export default defineComponent({
name: "App",
components: {
HelloWorld,
},
});
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.logo {
width: 100px;
height: 100px;
}
</style>
Binary file added template-cesium-vue-ts/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions template-cesium-vue-ts/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<h1>{{ msg }}</h1>
<div class="cesium-container" ref="mapRef" />
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
target="_blank"
>
Vetur
</a>
or
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
(if using
<code>&lt;script setup&gt;</code>)
</p>

<p>See <code>README.md</code> for more information.</p>

<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Docs
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>|
<a
href="https://cesium.com/docs/cesiumjs-ref-doc/index.html"
target="_blank"
>Cesium Documentation</a
>
</p>

<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>

<script lang="ts">
import { ref, defineComponent, onMounted } from "vue";
import { Viewer } from "cesium";
export default defineComponent({
name: "HelloWorld",
props: {
msg: {
type: String,
required: true,
},
},
setup: () => {
const mapRef = ref<HTMLDivElement | null>(null);
onMounted(() => {
mapRef.value && new Viewer(mapRef.value);
});
return { mapRef };
},
});
</script>

<style scoped>
a {
color: #42b983;
}
label {
margin: 0 0.5em;
font-weight: bold;
}
code {
background-color: #eee;
padding: 2px 4px;
border-radius: 4px;
color: #304455;
}
.cesium-container {
width: 500px;
height: 250px;
margin: 0 auto;
}
</style>
4 changes: 4 additions & 0 deletions template-cesium-vue-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
5 changes: 5 additions & 0 deletions template-cesium-vue-ts/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
15 changes: 15 additions & 0 deletions template-cesium-vue-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"types": ["vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
8 changes: 8 additions & 0 deletions template-cesium-vue-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import cesium from "vite-plugin-cesium";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), cesium()],
});
5 changes: 5 additions & 0 deletions template-cesium-vue/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
13 changes: 13 additions & 0 deletions template-cesium-vue/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" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions template-cesium-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "vite-vue-starter",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"cesium": "^1.80.0",
"vue": "^3.0.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.2.1",
"@vue/compiler-sfc": "^3.0.5",
"vite": "^2.1.5",
"vite-plugin-cesium": "^1.2.1"
}
}
Binary file added template-cesium-vue/public/favicon.ico
Binary file not shown.
26 changes: 26 additions & 0 deletions template-cesium-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<img id="logo" alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Hello Vue 3 + Vite + cesium" />
</template>

<script setup>
import HelloWorld from "./components/HelloWorld.vue";
// This starter template is using Vue 3 experimental <script setup> SFCs
// Check out https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
#logo {
width: 100px;
height: 100px;
}
</style>
Binary file added template-cesium-vue/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions template-cesium-vue/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<h1>{{ msg }}</h1>
<div class="cesium-container" ref="mapRef" />
<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Documentation
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>|
<a
href="https://cesium.com/docs/cesiumjs-ref-doc/index.html"
target="_blank"
>Cesium Documentation</a
>
</p>

<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>

<script setup>
import { ref, defineProps, onMounted } from "vue";
import { Viewer } from "cesium";
defineProps({
msg: String,
});
const mapRef = ref(null);
onMounted(() => {
const map = new Viewer(mapRef.value);
});
</script>

<style scoped>
a {
color: #42b983;
}
.cesium-container {
width: 500px;
height: 250px;
margin: 0 auto;
}
</style>
4 changes: 4 additions & 0 deletions template-cesium-vue/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
8 changes: 8 additions & 0 deletions template-cesium-vue/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import cesium from "vite-plugin-cesium";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), cesium()],
});

0 comments on commit c84fab6

Please sign in to comment.