mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
Add typescript compatibility
This commit is contained in:
parent
8a620dcc30
commit
01b02a9010
@ -1,5 +1,5 @@
|
|||||||
<% if (middleware) { %>
|
<% if (middleware) { %>
|
||||||
let files = require.context('~/middleware', false, /^\.\/.*\.js$/)
|
let files = require.context('~/middleware', false, /^\.\/.*\.(js|ts)$/)
|
||||||
let filenames = files.keys()
|
let filenames = files.keys()
|
||||||
|
|
||||||
function getModule (filename) {
|
function getModule (filename) {
|
||||||
@ -12,7 +12,7 @@ let middleware = {}
|
|||||||
|
|
||||||
// Generate the middleware
|
// Generate the middleware
|
||||||
for (let filename of filenames) {
|
for (let filename of filenames) {
|
||||||
let name = filename.replace(/^\.\//, '').replace(/\.js$/, '')
|
let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '')
|
||||||
middleware[name] = getModule(filename)
|
middleware[name] = getModule(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import Vue from 'vue'
|
|||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
let files = require.context('~/store', true, /^\.\/.*\.js$/)
|
let files = require.context('~/store', true, /^\.\/.*\.(js|ts)$/)
|
||||||
let filenames = files.keys()
|
let filenames = files.keys()
|
||||||
|
|
||||||
function getModule (filename) {
|
function getModule (filename) {
|
||||||
@ -30,7 +30,7 @@ let storeData = {}
|
|||||||
if (filenames.indexOf('./index.js') !== -1) {
|
if (filenames.indexOf('./index.js') !== -1) {
|
||||||
let mainModule = getModule('./index.js')
|
let mainModule = getModule('./index.js')
|
||||||
if (mainModule.commit) {
|
if (mainModule.commit) {
|
||||||
console.error('[nuxt.js] store/index.js should export raw store options instead of an instance.')
|
console.error('[nuxt.js] store/index should export raw store options instead of an instance.')
|
||||||
} else {
|
} else {
|
||||||
if (mainModule.state && typeof mainModule.state !== 'function') {
|
if (mainModule.state && typeof mainModule.state !== 'function') {
|
||||||
console.error('[nuxt.js] store state should be a function.')
|
console.error('[nuxt.js] store state should be a function.')
|
||||||
@ -43,7 +43,7 @@ if (filenames.indexOf('./index.js') !== -1) {
|
|||||||
if (store == null) {
|
if (store == null) {
|
||||||
storeData.modules = storeData.modules || {}
|
storeData.modules = storeData.modules || {}
|
||||||
for (let filename of filenames) {
|
for (let filename of filenames) {
|
||||||
let name = filename.replace(/^\.\//, '').replace(/\.js$/, '')
|
let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '')
|
||||||
if (name === 'index') continue
|
if (name === 'index') continue
|
||||||
|
|
||||||
let namePath = name.split(/\//)
|
let namePath = name.split(/\//)
|
||||||
|
Loading…
Reference in New Issue
Block a user