Skip to content

Commit 2168ed0

Browse files
committed
feat: initial batch of templates
1 parent 7785958 commit 2168ed0

File tree

12 files changed

+143
-26
lines changed

12 files changed

+143
-26
lines changed

docs/guide/build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ When it is time to deploy your app for production, simply run the `vite build` c
66

77
The production bundle assumes a baseline support for [Native ES modules dynamic imports](https://caniuse.com/es6-module-dynamic-import). By default, all code is minimally transpiled with target `es2020` (only for terser minification compatibility). You can specify the target range via the [`build.target` config option](/config/#build-target), where the lowest target available is `es2015`.
88

9-
Legacy browsers _can_ be supported via plugins that post-process the build output for compatibility (e.g. [`@rollup/plugin-babel`](https://github.com/rollup/plugins/tree/master/packages/babel) + [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) + [SystemJS](https://github.com/systemjs/systemjs)), however this is not a built-in feature.
9+
Legacy browsers _can_ be supported via plugins that post-process the build output for compatibility (e.g. [`@rollup/plugin-babel`](https://github.com/rollup/plugins/tree/master/packages/babel) + [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) + [SystemJS](https://github.com/systemjs/systemjs)). This is not a built-in feature, but there is plan to provide an official plugin that automatically emits a separate legacy bundle.
1010

1111
## Public Base Path
1212

packages/create-app/CHANGELOG.md

Whitespace-only changes.

packages/create-app/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ npm init @vitejs/app my-vue-app --template vue
2727

2828
Currently supported template presets include:
2929

30+
- `vanilla`
3031
- `vue`
3132
- `vue-ts`
3233
- `react`

packages/create-app/index.js

+35-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,30 @@ const path = require('path')
66
const argv = require('minimist')(process.argv.slice(2))
77
const { prompt } = require('enquirer')
88

9-
const targetDir = argv._[0] || '.'
109
const cwd = process.cwd()
11-
const root = path.join(cwd, targetDir)
10+
1211
const renameFiles = {
1312
_gitignore: '.gitignore'
1413
}
15-
console.log(`Scaffolding project in ${root}...`)
1614

1715
async function init() {
16+
let targetDir = argv._[0]
17+
if (!targetDir) {
18+
/**
19+
* @type {{ name: string }}
20+
*/
21+
const { name } = await prompt({
22+
type: 'input',
23+
name: 'name',
24+
message: `Project name:`,
25+
initial: 'vite-project'
26+
})
27+
targetDir = name
28+
}
29+
30+
const root = path.join(cwd, targetDir)
31+
console.log(`Scaffolding project in ${root}...`)
32+
1833
if (!fs.existsSync(root)) {
1934
fs.mkdirSync(root, { recursive: true })
2035
} else {
@@ -26,6 +41,7 @@ async function init() {
2641
const { yes } = await prompt({
2742
type: 'confirm',
2843
name: 'yes',
44+
initial: 'Y',
2945
message:
3046
`Target directory ${targetDir} is not empty.\n` +
3147
`Remove existing files and continue?`
@@ -38,10 +54,22 @@ async function init() {
3854
}
3955
}
4056

41-
const templateDir = path.join(
42-
__dirname,
43-
`template-${argv.t || argv.template || 'vue'}`
44-
)
57+
// determine template
58+
let template = argv.t || argv.template
59+
if (!template) {
60+
/**
61+
* @type {{ t: string }}
62+
*/
63+
const { t } = await prompt({
64+
type: 'select',
65+
name: 't',
66+
message: `Select a template:`,
67+
choices: ['vanilla', 'vue', 'vue-ts', 'react', 'react-ts']
68+
})
69+
template = t
70+
}
71+
72+
const templateDir = path.join(__dirname, `template-${template}`)
4573

4674
const write = (file, content) => {
4775
const targetPath = renameFiles[file]

packages/create-app/template-react-ts/src/App.tsx

+22-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,32 @@ function App() {
1111
<img src={logo} className="App-logo" alt="logo" />
1212
<p>Hello Vite + React!</p>
1313
<p>
14-
<button onClick={() => setCount(count => count + 1)}>count is: {count}</button>
14+
<button onClick={() => setCount((count) => count + 1)}>
15+
count is: {count}
16+
</button>
1517
</p>
1618
<p>
1719
Edit <code>App.tsx</code> and save to test HMR updates.
1820
</p>
19-
<a
20-
className="App-link"
21-
href="https://reactjs.org"
22-
target="_blank"
23-
rel="noopener noreferrer"
24-
>
25-
Learn React
26-
</a>
21+
<p>
22+
<a
23+
className="App-link"
24+
href="https://reactjs.org"
25+
target="_blank"
26+
rel="noopener noreferrer"
27+
>
28+
Learn React
29+
</a>
30+
{' | '}
31+
<a
32+
className="App-link"
33+
href="https://vitejs.dev/guide/features.html"
34+
target="_blank"
35+
rel="noopener noreferrer"
36+
>
37+
Vite Docs
38+
</a>
39+
</p>
2740
</header>
2841
</div>
2942
)

packages/create-app/template-react/src/App.jsx

+22-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,32 @@ function App() {
1111
<img src={logo} className="App-logo" alt="logo" />
1212
<p>Hello Vite + React!</p>
1313
<p>
14-
<button onClick={() => setCount(count => count + 1)}>count is: {count}</button>
14+
<button onClick={() => setCount((count) => count + 1)}>
15+
count is: {count}
16+
</button>
1517
</p>
1618
<p>
1719
Edit <code>App.jsx</code> and save to test HMR updates.
1820
</p>
19-
<a
20-
className="App-link"
21-
href="https://reactjs.org"
22-
target="_blank"
23-
rel="noopener noreferrer"
24-
>
25-
Learn React
26-
</a>
21+
<p>
22+
<a
23+
className="App-link"
24+
href="https://reactjs.org"
25+
target="_blank"
26+
rel="noopener noreferrer"
27+
>
28+
Learn React
29+
</a>
30+
{' | '}
31+
<a
32+
className="App-link"
33+
href="https://vitejs.dev/guide/features.html"
34+
target="_blank"
35+
rel="noopener noreferrer"
36+
>
37+
Vite Docs
38+
</a>
39+
</p>
2740
</header>
2841
</div>
2942
)
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="/main.js"></script>
12+
</body>
13+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import './style.css'
2+
3+
document.querySelector('#app').innerHTML = `
4+
<h1>Hello Vite!</h1>
5+
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
6+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "vite-starter",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build"
7+
},
8+
"devDependencies": {
9+
"vite": "^2.0.0-beta.1"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#app {
2+
font-family: Avenir, Helvetica, Arial, sans-serif;
3+
-webkit-font-smoothing: antialiased;
4+
-moz-osx-font-smoothing: grayscale;
5+
text-align: center;
6+
color: #2c3e50;
7+
margin-top: 60px;
8+
}

packages/create-app/template-vue-ts/src/components/HelloWorld.vue

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
22
<h1>{{ msg }}</h1>
3+
4+
<p>
5+
<a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Documentation</a> |
6+
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
7+
</p>
8+
39
<p>
410
Recommended setup:
511
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
@@ -46,3 +52,9 @@ export default defineComponent({
4652
}
4753
})
4854
</script>
55+
56+
<style scoped>
57+
a {
58+
color: #42b983;
59+
}
60+
</style>

packages/create-app/template-vue/src/components/HelloWorld.vue

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
22
<h1>{{ msg }}</h1>
3+
4+
<p>
5+
<a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Documentation</a> |
6+
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
7+
</p>
8+
39
<button @click="state.count++">count is: {{ state.count }}</button>
410
<p>
511
Edit
@@ -16,3 +22,9 @@ defineProps({
1622
1723
const state = reactive({ count: 0 })
1824
</script>
25+
26+
<style scoped>
27+
a {
28+
color: #42b983;
29+
}
30+
</style>

0 commit comments

Comments
 (0)