Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit 1b3d860

Browse files
fix(vite): typescript project generation (#316)
1 parent aabcb5e commit 1b3d860

File tree

15 files changed

+114
-85
lines changed

15 files changed

+114
-85
lines changed

packages/vue-cli-plugin-vuetify/generator/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ module.exports = (api, opts) => {
1010

1111
if (opts.preset !== 'configure') {
1212
opts = {
13+
hasTS: api.hasPlugin('typescript') || Object.keys(api.generator.pkg.devDependencies).includes('typescript'),
1314
...opts,
14-
...require(`../presets/${opts.preset}`).plugins['vue-cli-plugin-vuetify']
15+
...require(`../presets/${opts.preset}`).plugins['vue-cli-plugin-vuetify'],
1516
}
1617
}
1718

@@ -46,15 +47,15 @@ module.exports = (api, opts) => {
4647
polyfill.updateBabelConfig(api)
4748
polyfill.updateBrowsersList(api)
4849
}
49-
50+
5051
if (!opts.installFonts) fonts.addLinks(api, opts.iconFont)
5152
vuetify.setHtmlLang(api, opts.locale)
5253

5354
if (fileExists(api, 'src/public/index.html')) {
5455
fs.unlinkSync(api.resolve('src/public/index.html'))
5556
}
5657

57-
const configFile = api.resolve('./vue.config.js');
58+
const configFile = api.resolve('./vue.config.js')
5859

5960
if (fileExists(api, configFile)) {
6061
vuetify.addVuetifyLoaderDocsLink(configFile)

packages/vue-cli-plugin-vuetify/generator/templates/v3/src/components/HelloWorld.js.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<v-row class="text-center">
44
<v-col cols="12">
55
<v-img
6+
<%_ if (useVite) { _%>
67
:src="logo"
8+
<%_ } else { _%>
9+
:src="require('../assets/logo.svg')"
10+
<%_ } _%>
711
class="my-3"
812
contain
913
height="200"
@@ -12,12 +16,12 @@
1216

1317
<v-col class="mb-4">
1418
<h1 class="display-2 font-weight-bold mb-3">
15-
<div>Welcome to the Vuetify 3 Alpha</div>
19+
Welcome to the Vuetify 3 Alpha
1620
</h1>
1721

18-
<%_ if (useVite) { _%>
19-
<small>Vite Preview</small>
20-
<%_ } _%>
22+
<%_ if (useVite) { _%>
23+
<h4>Vite Preview</h4>
24+
<%_ } _%>
2125

2226
<p class="subheading font-weight-regular">
2327
For help and collaboration with other Vuetify developers,
@@ -96,7 +100,9 @@
96100
</template>
97101

98102
<script>
103+
<%_ if (useVite) { _%>
99104
import logo from '../assets/logo.svg'
105+
<%_ } _%>
100106
101107
export default {
102108
name: 'HelloWorld',
@@ -134,7 +140,9 @@ export default {
134140
href: 'https://medium.com/vuetify',
135141
},
136142
],
143+
<%_ if (useVite) { _%>
137144
logo,
145+
<%_ } _%>
138146
whatsNext: [
139147
{
140148
text: 'Explore components',

packages/vue-cli-plugin-vuetify/generator/templates/v3/src/components/HelloWorld.ts.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<v-row class="text-center">
44
<v-col cols="12">
55
<v-img
6+
<%_ if (useVite) { _%>
7+
:src="logo"
8+
<%_ } else { _%>
69
:src="require('../assets/logo.svg')"
10+
<%_ } _%>
711
class="my-3"
812
contain
913
height="200"
@@ -15,6 +19,10 @@
1519
Welcome to Vuetify V3 Alpha
1620
</h1>
1721

22+
<%_ if (useVite) { _%>
23+
<h4>Vite Preview</h4>
24+
<%_ } _%>
25+
1826
<p class="subheading font-weight-regular">
1927
For help and collaboration with other Vuetify developers,
2028
<br>please join our online
@@ -94,6 +102,11 @@
94102
<script lang='ts'>
95103
import { defineComponent } from 'vue'
96104
105+
<%_ if (useVite) { _%>
106+
// Logo
107+
import logo from '../assets/logo.svg'
108+
<%_ } _%>
109+
97110
export default defineComponent({
98111
name: 'HelloWorld',
99112
@@ -131,6 +144,9 @@ export default defineComponent({
131144
href: 'https://medium.com/vuetify',
132145
},
133146
],
147+
<%_ if (useVite) { _%>
148+
logo,
149+
<%_ } _%>
134150
whatsNext: [
135151
{
136152
text: 'Explore components',

packages/vue-cli-plugin-vuetify/generator/templates/v3/src/router/index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/vue-cli-plugin-vuetify/generator/templates/v3/src/router/index.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<template>
2-
<div>
3-
<HelloWorld/>
4-
</div>
2+
<HelloWorld />
53
</template>
64

75
<script>
6+
import { defineComponent } from 'vue';
7+
8+
// Components
89
import HelloWorld from '../components/HelloWorld.vue';
910
10-
export default {
11-
name: 'Home',
12-
11+
export default defineComponent({
12+
name: 'HomeView',
13+
1314
components: {
1415
HelloWorld,
1516
},
16-
};
17+
});
1718
</script>

packages/vue-cli-plugin-vuetify/generator/templates/v3/src/views/Home.ts.vue renamed to packages/vue-cli-plugin-vuetify/generator/templates/v3/src/views/HomeView.ts.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
<script lang="ts">
66
import { defineComponent } from 'vue';
7+
8+
// Components
79
import HelloWorld from '../components/HelloWorld.vue';
810
911
export default defineComponent({
10-
name: 'Home',
12+
name: 'HomeView',
1113
1214
components: {
1315
HelloWorld,

packages/vue-cli-plugin-vuetify/generator/templates/v3/vite/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
33
import vuetify from '@vuetify/vite-plugin'
44

5-
import path from 'path'
5+
const path = require('path')
66

77
// https://vitejs.dev/config/
88
export default defineConfig({
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig } from 'vite'
2+
import vue from '@vitejs/plugin-vue'
3+
import vuetify from '@vuetify/vite-plugin'
4+
5+
const path = require('path')
6+
7+
// https://vitejs.dev/config/
8+
export default defineConfig({
9+
plugins: [
10+
vue(),
11+
// https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vite-plugin
12+
vuetify({
13+
autoImport: true,
14+
}),
15+
],
16+
define: { 'process.env': {} },
17+
resolve: {
18+
alias: {
19+
'@': path.resolve(__dirname, 'src'),
20+
},
21+
},
22+
/* remove the need to specify .vue files https://vitejs.dev/config/#resolve-extensions
23+
resolve: {
24+
extensions: [
25+
'.js',
26+
'.json',
27+
'.jsx',
28+
'.mjs',
29+
'.ts',
30+
'.tsx',
31+
'.vue',
32+
]
33+
},
34+
*/
35+
})

packages/vue-cli-plugin-vuetify/generator/tools/alaCarte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function addDependencies (api, useV3) {
1010
api.extendPackage(deps)
1111
}
1212

13-
function addVueConfigPluginOptions(api) {
13+
function addVueConfigPluginOptions (api) {
1414
api.extendPackage({
1515
vue: {
1616
pluginOptions: {
@@ -30,7 +30,7 @@ function addVueConfigTranspileDependency (api) {
3030
})
3131
}
3232

33-
function addVueConfigVuetify(api, useV3) {
33+
function addVueConfigVuetify (api, useV3) {
3434
useV3 ? addVueConfigPluginOptions(api) : addVueConfigTranspileDependency(api)
3535
}
3636

0 commit comments

Comments
 (0)