|
1 | 1 | module.exports = (api, opts, rootOpts) => {
|
2 |
| - const helpers = require('./helpers')(api) |
3 |
| - |
4 |
| - api.extendPackage({ |
5 |
| - dependencies: { |
6 |
| - vuetify: "^1.1.11" |
7 |
| - } |
8 |
| - }) |
9 |
| - |
10 |
| - if (opts.useAlaCarte) { |
11 |
| - api.extendPackage({ |
12 |
| - devDependencies: { |
13 |
| - "babel-plugin-transform-imports": "^1.4.1", |
14 |
| - "stylus": "^0.54.5", |
15 |
| - "stylus-loader": "^3.0.1", |
16 |
| - } |
17 |
| - }) |
18 |
| - } |
19 |
| - |
20 |
| - if (opts.usePolyfill) { |
21 |
| - api.extendPackage({ |
22 |
| - devDependencies: { |
23 |
| - "@babel/polyfill": "^7.0.0-beta.49", |
24 |
| - } |
25 |
| - }) |
26 |
| - } |
27 |
| - |
28 |
| - if (api.hasPlugin('electron-builder') === true) { |
29 |
| - // material icons pkg for electron |
30 |
| - api.extendPackage({ |
31 |
| - devDependencies: { |
32 |
| - "material-design-icons-iconfont": "^3.0.3", |
33 |
| - } |
34 |
| - }) |
35 |
| - |
36 |
| - try { |
37 |
| - api.injectImports(helpers.getMain(), |
38 |
| - `import 'material-design-icons-iconfont/dist/material-design-icons.css'` |
39 |
| - ) |
40 |
| - } catch(e) { |
41 |
| - console.error(e) |
42 |
| - } |
43 |
| - } |
44 |
| - |
45 |
| - |
46 |
| - // Render vuetify plugin file |
47 |
| - api.render(api.hasPlugin('typescript') ? { |
48 |
| - './src/plugins/vuetify.ts': './templates/default/src/plugins/vuetify.ts' |
49 |
| - } : { |
50 |
| - './src/plugins/vuetify.js': './templates/default/src/plugins/vuetify.js' |
51 |
| - }, opts) |
52 |
| - |
53 |
| - // Render files if we're replacing |
54 |
| - const fs = require('fs') |
55 |
| - const routerPath = api.resolve('./src/router.js') |
56 |
| - opts.router = fs.existsSync(routerPath) |
57 |
| - |
58 |
| - if (opts.replaceComponents) { |
59 |
| - const files = { |
60 |
| - './src/App.vue': './templates/default/src/App.vue', |
61 |
| - './src/assets/logo.png': './templates/default/src/assets/logo.png' |
62 |
| - } |
63 |
| - |
64 |
| - if (opts.router) { |
65 |
| - files['./src/views/Home.vue'] = './templates/default/src/views/Home.vue' |
66 |
| - } else { |
67 |
| - api.render('./templates/hw') |
68 |
| - } |
69 |
| - |
70 |
| - api.render(files, opts) |
71 |
| - } |
| 2 | + const alaCarte = require('./tools/alaCarte') |
| 3 | + const fonts = require('./tools/fonts') |
| 4 | + const polyfill = require('./tools/polyfill') |
| 5 | + const vuetify = require('./tools/vuetify') |
| 6 | + |
| 7 | + vuetify.addDependencies(api) |
| 8 | + opts.useAlaCarte && alaCarte.addDependencies(api) |
| 9 | + opts.usePolyfill && polyfill.addDependencies(api) |
| 10 | + opts.installFonts && fonts.addDependencies(api, opts.iconFont) |
| 11 | + opts.installFonts && fonts.addImports(api, opts.iconFont) |
| 12 | + vuetify.renderFiles(api, opts) |
72 | 13 |
|
73 | 14 | // adapted from https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L68-L91
|
74 | 15 | api.onCreateComplete(() => {
|
75 |
| - // Modify main.js |
76 |
| - helpers.updateFile(helpers.getMain(), lines => { |
77 |
| - const vueImportIndex = lines.findIndex(line => line.match(/^import Vue/)) |
78 |
| - |
79 |
| - lines.splice(vueImportIndex + 1, 0, 'import \'./plugins/vuetify\'') |
80 |
| - |
81 |
| - return lines |
82 |
| - }) |
83 |
| - |
84 |
| - // Add polyfill |
85 |
| - if (opts.usePolyfill) { |
86 |
| - helpers.updateBabelConfig(cfg => { |
87 |
| - if (!cfg.presets) return cfg |
88 |
| - |
89 |
| - const vuePresetIndex = cfg.presets.findIndex(p => Array.isArray(p) ? p[0] === '@vue/app' : p === '@vue/app') |
90 |
| - const isArray = Array.isArray(cfg.presets[vuePresetIndex]) |
91 |
| - |
92 |
| - if (vuePresetIndex < 0) return cfg |
93 |
| - |
94 |
| - if (isArray) { |
95 |
| - cfg.presets[vuePresetIndex][1]['useBuiltIns'] = 'entry' |
96 |
| - } else { |
97 |
| - cfg.presets[vuePresetIndex] = [ |
98 |
| - '@vue/app', |
99 |
| - { |
100 |
| - useBuiltIns: 'entry' |
101 |
| - } |
102 |
| - ] |
103 |
| - } |
104 |
| - |
105 |
| - return cfg |
106 |
| - }) |
107 |
| - |
108 |
| - helpers.updateFile(helpers.getMain(), lines => { |
109 |
| - if (!lines.find(l => l.match(/^(import|require).*@babel\/polyfill.*$/))) { |
110 |
| - lines.unshift('import \'@babel/polyfill\'') |
111 |
| - } |
112 |
| - |
113 |
| - return lines |
114 |
| - }) |
115 |
| - } |
116 |
| - |
117 |
| - // If a-la-carte, update babel |
118 |
| - if (opts.useAlaCarte) { |
119 |
| - helpers.updateBabelConfig(cfg => { |
120 |
| - if (cfg.plugins === undefined) { |
121 |
| - cfg.plugins = [] |
122 |
| - } |
123 |
| - |
124 |
| - cfg.plugins.push([ |
125 |
| - 'transform-imports', |
126 |
| - { |
127 |
| - vuetify: { |
128 |
| - transform: 'vuetify/es5/components/${member}', |
129 |
| - preventFullImport: true |
130 |
| - } |
131 |
| - } |
132 |
| - ]) |
133 |
| - |
134 |
| - return cfg |
135 |
| - }) |
136 |
| - } |
137 |
| - |
138 |
| - // Add Material Icons (unless electron) |
139 |
| - if(api.hasPlugin('electron-builder') === false) { |
140 |
| - const indexPath = api.resolve('./public/index.html') |
141 |
| - |
142 |
| - let content = fs.readFileSync(indexPath, { encoding: 'utf8' }) |
143 |
| - |
144 |
| - const lines = content.split(/\r?\n/g).reverse() |
145 |
| - |
146 |
| - const lastLink = lines.findIndex(line => line.match(/^\s*<link/)) |
147 |
| - lines[lastLink] += '\n <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">' |
148 |
| - |
149 |
| - content = lines.reverse().join('\n') |
150 |
| - fs.writeFileSync(indexPath, content, { encoding: 'utf8' }) |
151 |
| - } |
| 16 | + vuetify.addImports(api) |
| 17 | + opts.usePolyfill && polyfill.updateBabelConfig(api) |
| 18 | + opts.usePolyfill && polyfill.addImports(api) |
| 19 | + opts.useAlaCarte && alaCarte.updateBabelConfig(api) |
| 20 | + !opts.installFonts && fonts.addLinks(api, opts.iconFont) |
| 21 | + vuetify.setHtmlLang(api, opts.locale) |
152 | 22 | })
|
153 | 23 | }
|
0 commit comments