Merge pull request #2417 from graphman65/dev

Add ignorePrefix option to ignore files
This commit is contained in:
Sébastien Chopin 2018-01-05 15:58:32 +01:00 committed by GitHub
commit b941b5e4d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<% if (middleware) { %>
let files = require.context('@/middleware', false, /^\.\/.*\.(<%= extensions %>)$/)
let files = require.context('@/middleware', false, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/)
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, /^\.\/.*\.(<%= extensions %>)$/)
const files = require.context('@/store', true, /^\.\/(?!<%= ignorePrefix %>).*\.(<%= extensions %>)$/)
const filenames = files.keys()
// Store

View File

@ -224,6 +224,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,
@ -235,7 +236,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: [`layouts/**/${this.options.ignorePrefix}*.{vue,js}`] })
let hasErrorLayout = false
layoutsFiles.forEach((file) => {
let name = file.split('/').slice(1).join('/').replace(/\.(vue|js)$/, '')
@ -264,7 +265,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

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

View File

@ -163,6 +163,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'
})