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

Commit 49eb66a

Browse files
committed
feat(generator): update for v2
1 parent 138eaa0 commit 49eb66a

File tree

6 files changed

+71
-78
lines changed

6 files changed

+71
-78
lines changed

generator/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,31 @@ module.exports = (api, opts) => {
88
opts = require(`../presets/${opts.preset}`).plugins['vue-cli-plugin-vuetify']
99
}
1010

11-
vuetify.addDependencies(api)
11+
// Add imports
12+
// Must be before dependencies because of weird bug
13+
vuetify.addImports(api)
14+
if (!opts.useAlaCarte && opts.usePolyfill) polyfill.addImports(api)
15+
if (opts.installFonts) fonts.addImports(api, opts.iconFont)
1216

13-
if (opts.useAlaCarte) {
14-
alaCarte.addDependencies(api)
15-
} else if (opts.usePolyfill) {
16-
polyfill.addDependencies(api)
17-
}
17+
// Add dependencies
18+
vuetify.addDependencies(api)
19+
if (opts.useAlaCarte) alaCarte.addDependencies(api)
20+
else if (opts.usePolyfill) polyfill.addDependencies(api)
1821

1922
if (opts.installFonts) {
2023
fonts.addDependencies(api, opts.iconFont)
21-
fonts.addImports(api, opts.iconFont)
2224
}
2325

26+
// Update templates
2427
vuetify.renderFiles(api, opts)
2528

2629
// adapted from https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L68-L91
2730
api.onCreateComplete(() => {
28-
vuetify.addImports(api)
2931
if (!opts.useAlaCarte && opts.usePolyfill) {
3032
polyfill.updateBabelConfig(api)
3133
polyfill.updateBrowsersList(api)
32-
polyfill.addImports(api)
3334
}
34-
!opts.installFonts && fonts.addLinks(api, opts.iconFont)
35+
if(!opts.installFonts) fonts.addLinks(api, opts.iconFont)
3536
vuetify.setHtmlLang(api, opts.locale)
3637
})
3738
}
Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Vue from 'vue'
22
<%_ if (useAlaCarte) { _%>
33
import Vuetify from 'vuetify/lib'
4-
import 'vuetify/src/stylus/app.styl'
54
<%_ } else { _%>
65
import Vuetify from 'vuetify'
76
import 'vuetify/dist/vuetify.min.css'
@@ -10,28 +9,36 @@ import 'vuetify/dist/vuetify.min.css'
109
import <%= locale.replace(/-/g, '') %> from 'vuetify/<%= typescript ? 'src' : 'es5' %>/locale/<%= locale %>'
1110
<%_ } _%>
1211

13-
Vue.use(Vuetify, {
14-
<%_ if (useTheme) { _%>
12+
Vue.use(Vuetify)
13+
14+
export default new Vuetify({
15+
<%_ if (useTheme) { _%>
1516
theme: {
16-
primary: '#ee44aa',
17-
secondary: '#424242',
18-
accent: '#82B1FF',
19-
error: '#FF5252',
20-
info: '#2196F3',
21-
success: '#4CAF50',
22-
warning: '#FFC107'
23-
},
24-
<%_ } _%>
25-
<%_ if (useCustomProperties) { _%>
26-
options: {
27-
customProperties: true
17+
<%_ if (useCustomProperties) { _%>
18+
options: {
19+
customProperties: true
20+
},
21+
<%_ } _%>
22+
themes: {
23+
light: {
24+
primary: '#ee44aa',
25+
secondary: '#424242',
26+
accent: '#82B1FF',
27+
error: '#FF5252',
28+
info: '#2196F3',
29+
success: '#4CAF50',
30+
warning: '#FFC107'
31+
}
32+
}
2833
},
29-
<%_ } _%>
30-
iconfont: '<%= iconFont %>',
31-
<%_ if (locale !== 'en') { _%>
32-
lang: {
33-
locales: { <%= locale.replace(/-/g, '') %> },
34-
current: '<%= locale %>'
35-
},
36-
<%_ } _%>
34+
<%_ } _%>
35+
<%_ if (locale !== 'en') { _%>
36+
lang: {
37+
locales: { <%= locale.replace(/-/g, '') %> },
38+
current: '<%= locale %>'
39+
},
40+
<%_ } _%>
41+
icons: {
42+
iconfont: '<%= iconFont %>',
43+
}
3744
})

generator/tools/alaCarte.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function addDependencies (api) {
22
api.extendPackage({
33
devDependencies: {
4-
"vuetify-loader": "^1.0.5",
5-
"stylus": "^0.54.5",
6-
"stylus-loader": "^3.0.1",
4+
"vuetify-loader": "^1.2.2",
5+
"sass": "^1.17.4",
6+
"sass-loader": "^7.1.0",
77
}
88
})
99
}

generator/tools/fonts.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,54 @@
11
const helpers = require('./helpers')
22
const fonts = {
3-
md: {
4-
'package': {
5-
'material-design-icons-iconfont': '^3.0.3',
3+
mdi: {
4+
package: {
5+
'@mdi/font': '^3.6.95',
66
},
7-
'import': 'material-design-icons-iconfont/dist/material-design-icons.css',
8-
link: '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">',
7+
import: '@mdi/font/css/materialdesignicons.css',
8+
link: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">',
99
},
10-
mdi: {
11-
'package': {
12-
'@mdi/font': '^2.6.95',
10+
md: {
11+
package: {
12+
'material-design-icons-iconfont': '^5.0.1',
1313
},
14-
'import': '@mdi/font/css/materialdesignicons.css',
15-
link: '<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css">',
14+
import: 'material-design-icons-iconfont/dist/material-design-icons.css',
15+
link: '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">',
1616
},
1717
fa: {
18-
'package': {
19-
'@fortawesome/fontawesome-free': '^5.2.0',
18+
package: {
19+
'@fortawesome/fontawesome-free': '^5.8.2',
2020
},
21-
'import': '@fortawesome/fontawesome-free/css/all.css',
22-
link: '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">',
21+
import: '@fortawesome/fontawesome-free/css/all.css',
22+
link: '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">',
2323
},
2424
fa4: {
25-
'package': {
25+
package: {
2626
'font-awesome': '^4.7.0',
2727
},
28-
'import': 'font-awesome/css/font-awesome.css',
28+
import: 'font-awesome/css/font-awesome.css',
2929
link: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">',
3030
},
3131
roboto: {
32-
'package': {
32+
package: {
3333
'roboto-fontface': '*',
3434
},
35-
'import': 'roboto-fontface/css/roboto/roboto-fontface.css',
35+
import: 'roboto-fontface/css/roboto/roboto-fontface.css',
3636
link: '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">',
3737
}
3838
}
3939

4040
function addDependencies (api, iconFont) {
4141
api.extendPackage({
4242
dependencies: {
43-
...fonts['roboto']['package'],
44-
...fonts[iconFont]['package'],
43+
...fonts.roboto.package,
44+
...fonts[iconFont].package,
4545
}
4646
})
4747
}
4848

4949
function addImports (api, iconFont) {
50-
try {
51-
api.injectImports(api.entryFile, `import '${fonts['roboto']['import']}'`)
52-
api.injectImports(api.entryFile, `import '${fonts[iconFont]['import']}'`)
53-
} catch(e) {
54-
console.error(e)
55-
}
50+
api.injectImports(api.entryFile, `import '${fonts.roboto.import}'`)
51+
api.injectImports(api.entryFile, `import '${fonts[iconFont].import}'`)
5652
}
5753

5854
function addLinks (api, iconFont) {

generator/tools/polyfill.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs')
44
function addDependencies (api) {
55
api.extendPackage({
66
dependencies: {
7-
"@babel/polyfill": "^7.0.0-rc.1",
7+
"@babel/polyfill": "^7.4.4",
88
}
99
})
1010
}
@@ -77,13 +77,7 @@ function updateBrowsersList (api) {
7777
}
7878

7979
function addImports (api) {
80-
helpers.updateFile(api, api.entryFile, lines => {
81-
if (!lines.find(l => l.match(/^(import|require).*@babel\/polyfill.*$/))) {
82-
lines.unshift('import \'@babel/polyfill\'')
83-
}
84-
85-
return lines
86-
})
80+
api.injectImports(api.entryFile, `import '@babel/polyfill'`)
8781
}
8882

8983
module.exports = {

generator/tools/vuetify.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const helpers = require('./helpers')
33
function addDependencies (api) {
44
api.extendPackage({
55
dependencies: {
6-
vuetify: "^1.5.5"
6+
vuetify: "^2.0.0-beta.0"
77
}
88
})
99
}
@@ -39,13 +39,8 @@ function renderFiles (api, opts) {
3939
}
4040

4141
function addImports (api) {
42-
helpers.updateFile(api, api.entryFile, lines => {
43-
const vueImportIndex = lines.findIndex(line => line.match(/^import Vue/))
44-
45-
lines.splice(vueImportIndex + 1, 0, `import './plugins/vuetify'`)
46-
47-
return lines
48-
})
42+
api.injectImports(api.entryFile, `import vuetify from './plugins/vuetify'`)
43+
api.injectRootOptions(api.entryFile, 'vuetify')
4944
}
5045

5146
function setHtmlLang (api, locale) {

0 commit comments

Comments
 (0)