Skip to content

Commit 09226b9

Browse files
author
Andrew Boyd
committed
updates nuxt module to expect external config file
1 parent fd7184e commit 09226b9

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

dist/nuxt/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/nuxt/plugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
/* eslint-disable */
21
import Vue from 'vue'
32
import VueFormulate from '@braid/vue-formulate'
3+
<% if (options.configPath) { %>
4+
import options from '<%= options.configPath %>'
5+
<% } else { %>
6+
const options = {}
7+
<% } %>
48

5-
Vue.use(VueFormulate, <%= serialize(options) %>)
9+
Vue.use(VueFormulate, options)

nuxt/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import fs from 'fs'
12
import path from 'path'
23

34
export default function nuxtVueFormulate (moduleOptions) {
4-
const formulateOptions = Object.assign({}, this.options.formulate, moduleOptions)
5+
let formulateOptions = Object.assign({}, this.options.formulate, moduleOptions)
6+
let configPath = false
7+
// check if we have a user-provided config path
8+
// or if a config file exists in the default location
9+
if (formulateOptions.configPath) {
10+
configPath = formulateOptions.configPath
11+
} else if (fs.existsSync(`${this.options.srcDir}/formulate.config.js`)) {
12+
configPath = '~/formulate.config.js'
13+
}
14+
// add the parsed config path back into the options object
15+
formulateOptions = Object.assign({}, formulateOptions, { configPath })
516
// Register `plugin.js` template
617
this.addPlugin({
718
src: path.resolve(__dirname, 'plugin.js'),

nuxt/plugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import Vue from 'vue'
22
import VueFormulate from '@braid/vue-formulate'
3+
<% if (options.configPath) { %>
4+
import options from '<%= options.configPath %>'
5+
<% } else { %>
6+
const options = {}
7+
<% } %>
38

4-
Vue.use(VueFormulate, <%= serialize(options) %>)
9+
Vue.use(VueFormulate, options)

0 commit comments

Comments
 (0)