mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
Add ignorePrefix option to ignore files
This commit is contained in:
parent
ae754af362
commit
45c15a96c4
@ -1,5 +1,5 @@
|
|||||||
<% if (middleware) { %>
|
<% if (middleware) { %>
|
||||||
let files = require.context('@/middleware', false, /^\.\/.*\.(js|ts)$/)
|
let files = require.context('@/middleware', false, /^\.\/(?!<%= ignorePrefix %>).*\.(js|ts)$/)
|
||||||
let filenames = files.keys()
|
let filenames = files.keys()
|
||||||
|
|
||||||
function getModule (filename) {
|
function getModule (filename) {
|
||||||
|
@ -4,7 +4,7 @@ import Vuex from 'vuex'
|
|||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
// Recursive find files in {srcDir}/store
|
// 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()
|
const filenames = files.keys()
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
|
@ -242,6 +242,7 @@ module.exports = class Builder {
|
|||||||
css: this.options.css,
|
css: this.options.css,
|
||||||
plugins: this.plugins,
|
plugins: this.plugins,
|
||||||
appPath: './App.js',
|
appPath: './App.js',
|
||||||
|
ignorePrefix: this.options.ignorePrefix,
|
||||||
layouts: Object.assign({}, this.options.layouts),
|
layouts: Object.assign({}, this.options.layouts),
|
||||||
loading: typeof this.options.loading === 'string' ? this.relativeToBuild(this.options.srcDir, this.options.loading) : this.options.loading,
|
loading: typeof this.options.loading === 'string' ? this.relativeToBuild(this.options.srcDir, this.options.loading) : this.options.loading,
|
||||||
transition: this.options.transition,
|
transition: this.options.transition,
|
||||||
@ -253,7 +254,7 @@ module.exports = class Builder {
|
|||||||
|
|
||||||
// -- Layouts --
|
// -- Layouts --
|
||||||
if (existsSync(resolve(this.options.srcDir, '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
|
let hasErrorLayout = false
|
||||||
layoutsFiles.forEach((file) => {
|
layoutsFiles.forEach((file) => {
|
||||||
let name = file.split('/').slice(1).join('/').replace(/\.(vue|js)$/, '')
|
let name = file.split('/').slice(1).join('/').replace(/\.(vue|js)$/, '')
|
||||||
@ -282,7 +283,7 @@ module.exports = class Builder {
|
|||||||
if (this._nuxtPages) {
|
if (this._nuxtPages) {
|
||||||
// Use nuxt.js createRoutes bases on pages/
|
// Use nuxt.js createRoutes bases on pages/
|
||||||
const files = {};
|
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)$/, '')
|
const key = f.replace(/\.(js|vue)$/, '')
|
||||||
if (/\.vue$/.test(f) || !files[key]) {
|
if (/\.vue$/.test(f) || !files[key]) {
|
||||||
files[key] = f
|
files[key] = f
|
||||||
|
@ -205,6 +205,7 @@ Options.defaults = {
|
|||||||
nuxtDir: resolve(__dirname, '../..'),
|
nuxtDir: resolve(__dirname, '../..'),
|
||||||
nuxtAppDir: resolve(__dirname, '../app'),
|
nuxtAppDir: resolve(__dirname, '../app'),
|
||||||
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
||||||
|
ignorePrefix: '-',
|
||||||
build: {
|
build: {
|
||||||
analyze: false,
|
analyze: false,
|
||||||
profile: process.argv.includes('--profile'),
|
profile: process.argv.includes('--profile'),
|
||||||
|
@ -159,6 +159,12 @@ test.serial('/users/1.html', async t => {
|
|||||||
t.false(existsSync(resolve(__dirname, 'fixtures/basic/dist', 'users/1/index.html')))
|
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
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after.always('Closing server', async t => {
|
test.after.always('Closing server', async t => {
|
||||||
await server.close()
|
await server.close()
|
||||||
|
3
test/fixtures/basic/middleware/-ignored.js
vendored
Normal file
3
test/fixtures/basic/middleware/-ignored.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default function () {
|
||||||
|
throw new Error('Should be ignored')
|
||||||
|
}
|
13
test/fixtures/basic/pages/-ignored.vue
vendored
Normal file
13
test/fixtures/basic/pages/-ignored.vue
vendored
Normal 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
3
test/fixtures/basic/store/-ignored.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const state = () => ({
|
||||||
|
error: 'Should be ignored'
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user