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

Commit 265f573

Browse files
chore(cli-plugin): clean up v3 template (#283)
Co-authored-by: John Leider <john.j.leider@gmail.com>
1 parent 70c490a commit 265f573

File tree

12 files changed

+82
-20
lines changed

12 files changed

+82
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = (api, opts) => {
1515
// Must be before dependencies because of weird bug
1616
if (!opts.useV3) vuetify.addImports(api)
1717
if (!opts.useAlaCarte && opts.usePolyfill) polyfill.addImports(api)
18-
if (opts.installFonts && !opts.useV3) fonts.addImports(api, opts.iconFont)
18+
if (opts.installFonts) opts.useV3 ? fonts.addPlugin(api, opts) : fonts.addImports(api, opts.iconFont)
1919

2020
// Add dependencies
2121
vuetify.addDependencies(api, opts.useV3)
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { createApp } from 'vue'
2-
import vuetify from './plugins/vuetify'
32
import App from './App.vue'
43
<%_ if (router) { _%>
54
import router from './router'
65
<%_ } _%>
76
<%_ if (store) { _%>
87
import store from './store'
98
<%_ } _%>
9+
import vuetify from './plugins/vuetify'
1010

11-
const app = createApp(App)
11+
<%_ if (useV3) { _%>
12+
loadFonts()
13+
<%_ } _%>
14+
15+
createApp(App)
1216
<%_ if (router) { _%>
13-
app.use(router)
17+
.use(router)
1418
<%_ } _%>
1519
<%_ if (store) { _%>
16-
app.use(store)
20+
.use(store)
1721
<%_ } _%>
18-
app.use(vuetify)
19-
20-
app.mount('#app')
22+
.use(vuetify)
23+
.mount('#app')
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { createApp } from 'vue'
2-
import vuetify from './plugins/vuetify'
32
import App from './App.vue'
43
<%_ if (router) { _%>
54
import router from './router'
65
<%_ } _%>
76
<%_ if (store) { _%>
87
import store from './store'
98
<%_ } _%>
9+
import vuetify from './plugins/vuetify'
10+
11+
<%_ if (useV3) { _%>
12+
loadFonts()
13+
<%_ } _%>
1014

1115
createApp(App)
12-
<%_ if (router) { _%>
16+
<%_ if (router) { _%>
1317
.use(router)
14-
<%_ } _%>
15-
<%_ if (store) { _%>
18+
<%_ } _%>
19+
<%_ if (store) { _%>
1620
.use(store)
17-
<%_ } _%>
21+
<%_ } _%>
1822
.use(vuetify)
1923
.mount('#app')

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// Styles
12
import '@mdi/font/css/materialdesignicons.css'
23
import 'vuetify/styles'
4+
5+
// Vuetify
36
import { createVuetify } from 'vuetify'
47

58
export default createVuetify(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* plugins/webfontloader.js
3+
*
4+
* webfontloader documentation: https://github.com/typekit/webfontloader
5+
*/
6+
7+
export async function loadFonts () {
8+
const webFontLoader = await import(/* webpackChunkName: "webfontloader" */'webfontloader')
9+
10+
webFontLoader.load({
11+
google: {
12+
families: ['Roboto:100,300,400,500,700,900&display=swap'],
13+
},
14+
})
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* plugins/webfontloader.js
3+
*
4+
* webfontloader documentation: https://github.com/typekit/webfontloader
5+
*/
6+
7+
export async function loadFonts () {
8+
const webFontLoader = await import(/* webpackChunkName: "webfontloader" */'webfontloader')
9+
10+
webFontLoader.load({
11+
google: {
12+
families: ['Roboto:100,300,400,500,700,900&display=swap'],
13+
},
14+
})
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Place SASS variable overrides here
2+
// $font-size-root: 18px;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,27 @@ function addLinks (api, iconFont) {
6767
})
6868
}
6969

70+
function addPlugin(api, opts) {
71+
opts.hasTS = api.hasPlugin('typescript')
72+
const ext = opts.hasTS ? 'ts' : 'js'
73+
74+
api.injectImports(api.entryFile, `import { loadFonts } from './plugins/webfontloader'`)
75+
76+
api.extendPackage({
77+
dependencies: {
78+
webfontloader: '^1.0.0',
79+
},
80+
...(opts.hasTS && { devDependencies: { '@types/webfontloader': '^1.0.0' }, }),
81+
})
82+
83+
api.render({
84+
[`./src/plugins/webfontloader.${ext}`]: `../templates/v3/vite/plugins/webfontloader.${ext}`,
85+
}, opts)
86+
}
87+
7088
module.exports = {
7189
addDependencies,
7290
addImports,
7391
addLinks,
92+
addPlugin,
7493
}

0 commit comments

Comments
 (0)