mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
feat: Add extensions option to add more language support
This commit is contained in:
parent
dd83c87f64
commit
5b923fd97e
@ -1,5 +1,5 @@
|
||||
<% if (middleware) { %>
|
||||
let files = require.context('@/middleware', false, /^\.\/.*\.(js|ts)$/)
|
||||
let files = require.context('@/middleware', false, /^\.\/.*\.(<%= extensions %>)$/)
|
||||
let filenames = files.keys()
|
||||
|
||||
function getModule (filename) {
|
||||
@ -12,7 +12,7 @@ let middleware = {}
|
||||
|
||||
// Generate the middleware
|
||||
for (let filename of filenames) {
|
||||
let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '')
|
||||
let name = filename.replace(/^\.\//, '').replace(/\.(<%= extensions %>)$/, '')
|
||||
middleware[name] = getModule(filename)
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import Vuex from 'vuex'
|
||||
Vue.use(Vuex)
|
||||
|
||||
// Recursive find files in {srcDir}/store
|
||||
const files = require.context('@/store', true, /^\.\/.*\.(js|ts)$/)
|
||||
const files = require.context('@/store', true, /^\.\/.*\.(<%= extensions %>)$/)
|
||||
const filenames = files.keys()
|
||||
|
||||
// Store
|
||||
@ -30,7 +30,7 @@ if (typeof storeData !== 'function') {
|
||||
}
|
||||
|
||||
for (let filename of filenames) {
|
||||
let name = filename.replace(/^\.\//, '').replace(/\.(js|ts)$/, '')
|
||||
let name = filename.replace(/^\.\//, '').replace(/\.(<%= extensions %>)$/, '')
|
||||
if (name === 'index') continue
|
||||
|
||||
let namePath = name.split(/\//)
|
||||
|
@ -210,6 +210,7 @@ module.exports = class Builder {
|
||||
]
|
||||
const templateVars = {
|
||||
options: this.options,
|
||||
extensions: this.options.extensions.map((ext) => ext.replace(/^\./, '')).join('|'),
|
||||
messages: this.options.messages,
|
||||
uniqBy: _.uniqBy,
|
||||
isDev: this.options.dev,
|
||||
|
@ -31,6 +31,9 @@ Options.from = function (_options) {
|
||||
if (typeof options.layoutTransition === 'string') {
|
||||
options.layoutTransition = { name: options.layoutTransition }
|
||||
}
|
||||
if (typeof options.extensions === 'string') {
|
||||
options.extensions = [ options.extensions ]
|
||||
}
|
||||
|
||||
const hasValue = v => typeof v === 'string' && v
|
||||
options.rootDir = hasValue(options.rootDir) ? options.rootDir : process.cwd()
|
||||
@ -58,6 +61,11 @@ Options.from = function (_options) {
|
||||
.filter(dir => hasValue(dir))
|
||||
.map(dir => resolve(options.rootDir, dir))
|
||||
|
||||
// Sanitize extensions
|
||||
if (options.extensions.indexOf('js') === -1) {
|
||||
options.extensions.unshift('js')
|
||||
}
|
||||
|
||||
// If app.html is defined, set the template path to the user template
|
||||
options.appTemplatePath = resolve(options.buildDir, 'views/app.template.html')
|
||||
if (existsSync(join(options.srcDir, 'app.html'))) {
|
||||
@ -143,6 +151,7 @@ Options.defaults = {
|
||||
nuxtDir: resolve(__dirname, '../..'),
|
||||
nuxtAppDir: resolve(__dirname, '../app'),
|
||||
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
||||
extensions: [],
|
||||
build: {
|
||||
analyze: false,
|
||||
profile: process.argv.includes('--profile'),
|
||||
|
Loading…
Reference in New Issue
Block a user