Skip to content

Commit 78495a3

Browse files
authored
feat: vuetifyOptions through options file (#86)
1 parent d285b3b commit 78495a3

File tree

7 files changed

+34
-20
lines changed

7 files changed

+34
-20
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ dist
55
coverage
66

77
# Plugin
8-
lib/plugin.js
8+
lib/templates

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module.exports = {
33
collectCoverage: true,
44
collectCoverageFrom: [
55
'lib/**/*.js',
6-
'!lib/plugin.js'
6+
'!lib/templates/**'
77
]
88
}

lib/module.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path')
2+
const fs = require('fs')
23
const merge = require('deepmerge')
34

45
const defaults = {
@@ -100,10 +101,20 @@ module.exports = function (moduleOptions) {
100101
delete vuetifyOptions.defaultAssets
101102
delete vuetifyOptions.treeShake
102103

104+
const app = this.options.dir.app || 'app'
105+
const userOptions = path.join(this.options.srcDir, app, 'vuetify', 'options.js')
106+
const userOptionsExists = fs.existsSync(userOptions)
107+
108+
this.addTemplate({
109+
fileName: 'vuetify/options.js',
110+
src: userOptionsExists ? userOptions : path.join(__dirname, 'templates/options.js'),
111+
options: vuetifyOptions
112+
})
113+
103114
// Register plugin
104115
this.addPlugin({
105-
src: path.resolve(__dirname, 'plugin.js'),
106-
fileName: 'vuetify.js',
116+
fileName: 'vuetify/plugin.js',
117+
src: path.resolve(__dirname, 'templates/plugin.js'),
107118
options: {
108119
defaultIconPreset,
109120
treeShake: options.treeShake,

lib/templates/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default <%= serializeFunction(options) %>

lib/plugin.js renamed to lib/templates/plugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import Vue from 'vue'
22
import Vuetify from '<%= options.treeShake ? 'vuetify/lib' : 'vuetify' %>'
3+
import options from './options'
34

45
Vue.use(Vuetify)
56

6-
const options = <%= serializeFunction(options.vuetifyOptions) %>
7-
87
<% if (options.defaultIconPreset) { %>
98
options.icons = options.icons || {}
109
options.icons.iconfont = '<%= options.defaultIconPreset %>'

test/fixture/app/vuetify/options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import colors from 'vuetify/es5/util/colors'
2+
3+
export default {
4+
theme: {
5+
dark: true,
6+
themes: {
7+
dark: {
8+
primary: colors.red.base
9+
}
10+
}
11+
}
12+
}

test/fixture/nuxt.config.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { resolve } = require('path')
2-
const colors = require('vuetify/es5/util/colors').default
32

43
module.exports = {
54
rootDir: resolve(__dirname, '../..'),
@@ -11,18 +10,10 @@ module.exports = {
1110
},
1211

1312
modules: [
14-
require('../..')
15-
],
16-
17-
vuetify: {
18-
customVariables: ['~/assets/variables.scss'],
19-
theme: {
20-
dark: true,
21-
themes: {
22-
dark: {
23-
primary: colors.red
24-
}
13+
[
14+
require('../..'), {
15+
customVariables: ['~/assets/variables.scss']
2516
}
26-
}
27-
}
17+
]
18+
]
2819
}

0 commit comments

Comments
 (0)