mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
Moved options to a new dir
block:
This commit is contained in:
parent
483cd9ea29
commit
536aab6380
@ -137,15 +137,15 @@ module.exports = class Builder {
|
|||||||
// Check if pages dir exists and warn if not
|
// Check if pages dir exists and warn if not
|
||||||
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
||||||
if (this._nuxtPages) {
|
if (this._nuxtPages) {
|
||||||
if (!existsSync(join(this.options.srcDir, this.options.pagesDir))) {
|
if (!existsSync(join(this.options.srcDir, this.options.dir.pages))) {
|
||||||
let dir = this.options.srcDir
|
let dir = this.options.srcDir
|
||||||
if (existsSync(join(this.options.srcDir, '..', this.options.pagesDir))) {
|
if (existsSync(join(this.options.srcDir, '..', this.options.dir.pages))) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`No \`${this.options.pagesDir}\` directory found in ${dir}. Did you mean to run \`nuxt\` in the parent (\`../\`) directory?`
|
`No \`${this.options.dir.pages}\` directory found in ${dir}. Did you mean to run \`nuxt\` in the parent (\`../\`) directory?`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Couldn't find a \`${this.options.pagesDir}\` directory in ${dir}. Please create one under the project root`
|
`Couldn't find a \`${this.options.dir.pages}\` directory in ${dir}. Please create one under the project root`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +314,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(`${this.options.pagesDir}/**/*.{vue,js}`, {
|
;(await glob(`${this.options.dir.pages}/**/*.{vue,js}`, {
|
||||||
cwd: this.options.srcDir,
|
cwd: this.options.srcDir,
|
||||||
ignore: this.options.ignore
|
ignore: this.options.ignore
|
||||||
})).forEach(f => {
|
})).forEach(f => {
|
||||||
@ -326,7 +326,7 @@ module.exports = class Builder {
|
|||||||
templateVars.router.routes = createRoutes(
|
templateVars.router.routes = createRoutes(
|
||||||
Object.values(files),
|
Object.values(files),
|
||||||
this.options.srcDir,
|
this.options.srcDir,
|
||||||
this.options.pagesDir
|
this.options.dir.pages
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
templateVars.router.routes = this.options.build.createRoutes(
|
templateVars.router.routes = this.options.build.createRoutes(
|
||||||
@ -647,9 +647,9 @@ module.exports = class Builder {
|
|||||||
]
|
]
|
||||||
if (this._nuxtPages) {
|
if (this._nuxtPages) {
|
||||||
patterns.push(
|
patterns.push(
|
||||||
r(src, this.options.pagesDir),
|
r(src, this.options.dir.pages),
|
||||||
r(src, `${this.options.pagesDir}/*.{vue,js}`),
|
r(src, `${this.options.dir.pages}/*.{vue,js}`),
|
||||||
r(src, `${this.options.pagesDir}/**/*.{vue,js}`)
|
r(src, `${this.options.dir.pages}/**/*.{vue,js}`)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
patterns = _.map(patterns, p => upath.normalizeSafe(p))
|
patterns = _.map(patterns, p => upath.normalizeSafe(p))
|
||||||
|
@ -27,7 +27,7 @@ module.exports = class Generator {
|
|||||||
this.builder = builder
|
this.builder = builder
|
||||||
|
|
||||||
// Set variables
|
// Set variables
|
||||||
this.staticRoutes = resolve(this.options.srcDir, this.options.staticDir)
|
this.staticRoutes = resolve(this.options.srcDir, this.options.dir.static)
|
||||||
this.srcBuiltPath = resolve(this.options.buildDir, 'dist')
|
this.srcBuiltPath = resolve(this.options.buildDir, 'dist')
|
||||||
this.distPath = resolve(this.options.rootDir, this.options.generate.dir)
|
this.distPath = resolve(this.options.rootDir, this.options.generate.dir)
|
||||||
this.distNuxtPath = join(
|
this.distNuxtPath = join(
|
||||||
|
@ -23,8 +23,8 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
|
|||||||
|
|
||||||
// Used by vue-loader so we can use in templates
|
// Used by vue-loader so we can use in templates
|
||||||
// with <img src="~/assets/nuxt.png"/>
|
// with <img src="~/assets/nuxt.png"/>
|
||||||
configAlias[this.options.assetsDir] = join(this.options.srcDir, this.options.assetsDir)
|
configAlias[this.options.dir.assets] = join(this.options.srcDir, this.options.dir.assets)
|
||||||
configAlias[this.options.staticDir] = join(this.options.srcDir, this.options.staticDir)
|
configAlias[this.options.dir.static] = join(this.options.srcDir, this.options.dir.static)
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
name,
|
name,
|
||||||
|
@ -57,8 +57,8 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
|
|||||||
// css-loader
|
// css-loader
|
||||||
// https://github.com/webpack-contrib/css-loader
|
// https://github.com/webpack-contrib/css-loader
|
||||||
const cssLoaderAlias = {}
|
const cssLoaderAlias = {}
|
||||||
cssLoaderAlias[`/${this.options.assetsDir}`] = join(this.options.srcDir, this.options.assetsDir)
|
cssLoaderAlias[`/${this.options.dir.assets}`] = join(this.options.srcDir, this.options.dir.assets)
|
||||||
cssLoaderAlias[`/${this.options.staticDir}`] = join(this.options.srcDir, this.options.staticDir)
|
cssLoaderAlias[`/${this.options.dir.static}`] = join(this.options.srcDir, this.options.dir.static)
|
||||||
|
|
||||||
loaders.unshift({
|
loaders.unshift({
|
||||||
loader: 'css-loader',
|
loader: 'css-loader',
|
||||||
|
@ -284,9 +284,11 @@ Options.defaults = {
|
|||||||
name: 'layout',
|
name: 'layout',
|
||||||
mode: 'out-in'
|
mode: 'out-in'
|
||||||
},
|
},
|
||||||
assetsDir: 'assets',
|
dir: {
|
||||||
pagesDir: 'pages',
|
assets: 'assets',
|
||||||
staticDir: 'static',
|
pages: 'pages',
|
||||||
|
static: 'static'
|
||||||
|
},
|
||||||
router: {
|
router: {
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: '/',
|
base: '/',
|
||||||
|
@ -251,7 +251,7 @@ module.exports = class Renderer {
|
|||||||
// For serving static/ files to /
|
// For serving static/ files to /
|
||||||
this.useMiddleware(
|
this.useMiddleware(
|
||||||
serveStatic(
|
serveStatic(
|
||||||
resolve(this.options.srcDir, this.options.staticDir),
|
resolve(this.options.srcDir, this.options.dir.static),
|
||||||
this.options.render.static
|
this.options.render.static
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
10
test/fixtures/custom-dirs/nuxt.config.js
vendored
10
test/fixtures/custom-dirs/nuxt.config.js
vendored
@ -1,6 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
assetsDir: 'custom-assets',
|
css: [{ src: '~/custom-assets/app.css' }],
|
||||||
pagesDir: 'custom-pages',
|
dir: {
|
||||||
staticDir: 'custom-static',
|
assets: 'custom-assets',
|
||||||
css: [{ src: '~/custom-assets/app.css' }]
|
pages: 'custom-pages',
|
||||||
|
static: 'custom-static'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user