diff --git a/lib/app/store.js b/lib/app/store.js index 94c398254e..831e87f664 100644 --- a/lib/app/store.js +++ b/lib/app/store.js @@ -3,14 +3,14 @@ import Vuex from 'vuex' Vue.use(Vuex) -// Recursive find files in {srcDir}/store -const files = require.context('@/store', true, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/) +// Recursive find files in {srcDir}/{dir.store} +const files = require.context('@/<%= dir.store %>', true, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/) const filenames = files.keys() // Store let storeData = {} -// Check if store/index.js exists +// Check if {dir.store}/index.js exists let indexFilename filenames.forEach((filename) => { if (filename.indexOf('./index.') !== -1) { @@ -57,10 +57,10 @@ function getModule (filename) { const file = files(filename) const module = file.default || file if (module.commit) { - throw new Error('[nuxt] store/' + filename.replace('./', '') + ' should export a method which returns a Vuex instance.') + throw new Error('[nuxt] <%= dir.store %>/' + filename.replace('./', '') + ' should export a method which returns a Vuex instance.') } if (module.state && typeof module.state !== 'function') { - throw new Error('[nuxt] state should be a function in store/' + filename.replace('./', '')) + throw new Error('[nuxt] state should be a function in <%= dir.store %>/' + filename.replace('./', '')) } return module } diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 4c9d47c821..67f0217765 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -641,7 +641,7 @@ module.exports = class Builder { const src = this.options.srcDir let patterns = [ r(src, this.options.dir.layouts), - r(src, 'store'), + r(src, this.options.dir.store), r(src, this.options.dir.middleware), r(src, `${this.options.dir.layouts}/*.{vue,js}`), r(src, `${this.options.dir.layouts}/**/*.{vue,js}`) diff --git a/lib/common/options.js b/lib/common/options.js index 5fdbe71133..6c5fab4a6b 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -85,7 +85,7 @@ Options.from = function (_options) { } // If store defined, update store options to true unless explicitly disabled - if (options.store !== false && existsSync(join(options.srcDir, 'store'))) { + if (options.store !== false && existsSync(join(options.srcDir, options.dir.store))) { options.store = true } @@ -289,7 +289,8 @@ Options.defaults = { layouts: 'layouts', middleware: 'middleware', pages: 'pages', - static: 'static' + static: 'static', + store: 'store' }, router: { mode: 'history', diff --git a/test/fixtures/custom-dirs/custom-store/index.js b/test/fixtures/custom-dirs/custom-store/index.js new file mode 100644 index 0000000000..3eb99f46e0 --- /dev/null +++ b/test/fixtures/custom-dirs/custom-store/index.js @@ -0,0 +1,17 @@ +import Vue from 'vue' +import Vuex from 'vuex' + +Vue.use(Vuex) + +const store = () => new Vuex.Store({ + state: { + counter: 0 + }, + mutations: { + increment(state) { + state.counter++ + } + } +}) + +export default store diff --git a/test/fixtures/custom-dirs/nuxt.config.js b/test/fixtures/custom-dirs/nuxt.config.js index b98932dad7..f150701a46 100644 --- a/test/fixtures/custom-dirs/nuxt.config.js +++ b/test/fixtures/custom-dirs/nuxt.config.js @@ -5,6 +5,7 @@ module.exports = { layouts: 'custom-layouts', middleware: 'custom-middleware', pages: 'custom-pages', - static: 'custom-static' + static: 'custom-static', + store: 'custom-store' } }