feat: Add extensions option to add more language support

This commit is contained in:
Sébastien Chopin 2018-01-04 18:10:17 +01:00
parent dd83c87f64
commit 5b923fd97e
4 changed files with 14 additions and 4 deletions

View File

@ -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)
}

View File

@ -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(/\//)

View File

@ -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,

View File

@ -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'),