Add ignorePrefix option to ignore files

This commit is contained in:
Sebastien Lacoste 2017-12-18 16:53:36 +01:00
parent ae754af362
commit 45c15a96c4
8 changed files with 31 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, /^\.\/(?!<%= ignorePrefix %>).*\.(js|ts)$/)
let filenames = files.keys()
function 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, /^\.\/(?!<%= ignorePrefix %>).*\.(js|ts)$/)
const filenames = files.keys()
// Store

View File

@ -242,6 +242,7 @@ module.exports = class Builder {
css: this.options.css,
plugins: this.plugins,
appPath: './App.js',
ignorePrefix: this.options.ignorePrefix,
layouts: Object.assign({}, this.options.layouts),
loading: typeof this.options.loading === 'string' ? this.relativeToBuild(this.options.srcDir, this.options.loading) : this.options.loading,
transition: this.options.transition,
@ -253,7 +254,7 @@ module.exports = class Builder {
// -- Layouts --
if (existsSync(resolve(this.options.srcDir, 'layouts'))) {
const layoutsFiles = await glob('layouts/**/*.{vue,js}', { cwd: this.options.srcDir })
const layoutsFiles = await glob('layouts/**/*.{vue,js}', { cwd: this.options.srcDir, ignore: [`pages/**/${this.options.ignorePrefix}*.{vue,js}`] })
let hasErrorLayout = false
layoutsFiles.forEach((file) => {
let name = file.split('/').slice(1).join('/').replace(/\.(vue|js)$/, '')
@ -282,7 +283,7 @@ module.exports = class Builder {
if (this._nuxtPages) {
// Use nuxt.js createRoutes bases on pages/
const files = {};
(await glob('pages/**/*.{vue,js}', { cwd: this.options.srcDir })).forEach(f => {
(await glob('pages/**/*.{vue,js}', { cwd: this.options.srcDir, ignore: [`pages/**/${this.options.ignorePrefix}*.{vue,js}`] })).forEach(f => {
const key = f.replace(/\.(js|vue)$/, '')
if (/\.vue$/.test(f) || !files[key]) {
files[key] = f

View File

@ -205,6 +205,7 @@ Options.defaults = {
nuxtDir: resolve(__dirname, '../..'),
nuxtAppDir: resolve(__dirname, '../app'),
modulesDir: ['node_modules'], // ~> relative to options.rootDir
ignorePrefix: '-',
build: {
analyze: false,
profile: process.argv.includes('--profile'),

View File

@ -159,6 +159,12 @@ test.serial('/users/1.html', async t => {
t.false(existsSync(resolve(__dirname, 'fixtures/basic/dist', 'users/1/index.html')))
})
test.serial('/-ignored', async t => {
const error = await t.throws(rp(url('/-ignored')))
t.true(error.statusCode === 404)
t.true(error.response.body.includes('Cannot GET /-ignored'))
})
// Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server', async t => {
await server.close()

View File

@ -0,0 +1,3 @@
export default function () {
throw new Error('Should be ignored')
}

13
test/fixtures/basic/pages/-ignored.vue vendored Normal file
View File

@ -0,0 +1,13 @@
<template lang="html">
<div class="error">
Should be ignored
</div>
</template>
<script>
export default {
}
</script>
<style lang="css">
</style>

3
test/fixtures/basic/store/-ignored.js vendored Normal file
View File

@ -0,0 +1,3 @@
export const state = () => ({
error: 'Should be ignored'
})