mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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
|
||||
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
||||
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
|
||||
if (existsSync(join(this.options.srcDir, '..', this.options.pagesDir))) {
|
||||
if (existsSync(join(this.options.srcDir, '..', this.options.dir.pages))) {
|
||||
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 {
|
||||
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) {
|
||||
// Use nuxt.js createRoutes bases on pages/
|
||||
const files = {}
|
||||
;(await glob(`${this.options.pagesDir}/**/*.{vue,js}`, {
|
||||
;(await glob(`${this.options.dir.pages}/**/*.{vue,js}`, {
|
||||
cwd: this.options.srcDir,
|
||||
ignore: this.options.ignore
|
||||
})).forEach(f => {
|
||||
@ -326,7 +326,7 @@ module.exports = class Builder {
|
||||
templateVars.router.routes = createRoutes(
|
||||
Object.values(files),
|
||||
this.options.srcDir,
|
||||
this.options.pagesDir
|
||||
this.options.dir.pages
|
||||
)
|
||||
} else {
|
||||
templateVars.router.routes = this.options.build.createRoutes(
|
||||
@ -647,9 +647,9 @@ module.exports = class Builder {
|
||||
]
|
||||
if (this._nuxtPages) {
|
||||
patterns.push(
|
||||
r(src, this.options.pagesDir),
|
||||
r(src, `${this.options.pagesDir}/*.{vue,js}`),
|
||||
r(src, `${this.options.pagesDir}/**/*.{vue,js}`)
|
||||
r(src, this.options.dir.pages),
|
||||
r(src, `${this.options.dir.pages}/*.{vue,js}`),
|
||||
r(src, `${this.options.dir.pages}/**/*.{vue,js}`)
|
||||
)
|
||||
}
|
||||
patterns = _.map(patterns, p => upath.normalizeSafe(p))
|
||||
|
@ -27,7 +27,7 @@ module.exports = class Generator {
|
||||
this.builder = builder
|
||||
|
||||
// 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.distPath = resolve(this.options.rootDir, this.options.generate.dir)
|
||||
this.distNuxtPath = join(
|
||||
|
@ -23,8 +23,8 @@ module.exports = function webpackBaseConfig({ name, isServer }) {
|
||||
|
||||
// Used by vue-loader so we can use in templates
|
||||
// with <img src="~/assets/nuxt.png"/>
|
||||
configAlias[this.options.assetsDir] = join(this.options.srcDir, this.options.assetsDir)
|
||||
configAlias[this.options.staticDir] = join(this.options.srcDir, this.options.staticDir)
|
||||
configAlias[this.options.dir.assets] = join(this.options.srcDir, this.options.dir.assets)
|
||||
configAlias[this.options.dir.static] = join(this.options.srcDir, this.options.dir.static)
|
||||
|
||||
const config = {
|
||||
name,
|
||||
|
@ -57,8 +57,8 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
|
||||
// css-loader
|
||||
// https://github.com/webpack-contrib/css-loader
|
||||
const cssLoaderAlias = {}
|
||||
cssLoaderAlias[`/${this.options.assetsDir}`] = join(this.options.srcDir, this.options.assetsDir)
|
||||
cssLoaderAlias[`/${this.options.staticDir}`] = join(this.options.srcDir, this.options.staticDir)
|
||||
cssLoaderAlias[`/${this.options.dir.assets}`] = join(this.options.srcDir, this.options.dir.assets)
|
||||
cssLoaderAlias[`/${this.options.dir.static}`] = join(this.options.srcDir, this.options.dir.static)
|
||||
|
||||
loaders.unshift({
|
||||
loader: 'css-loader',
|
||||
|
@ -284,9 +284,11 @@ Options.defaults = {
|
||||
name: 'layout',
|
||||
mode: 'out-in'
|
||||
},
|
||||
assetsDir: 'assets',
|
||||
pagesDir: 'pages',
|
||||
staticDir: 'static',
|
||||
dir: {
|
||||
assets: 'assets',
|
||||
pages: 'pages',
|
||||
static: 'static'
|
||||
},
|
||||
router: {
|
||||
mode: 'history',
|
||||
base: '/',
|
||||
|
@ -251,7 +251,7 @@ module.exports = class Renderer {
|
||||
// For serving static/ files to /
|
||||
this.useMiddleware(
|
||||
serveStatic(
|
||||
resolve(this.options.srcDir, this.options.staticDir),
|
||||
resolve(this.options.srcDir, this.options.dir.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 = {
|
||||
assetsDir: 'custom-assets',
|
||||
pagesDir: 'custom-pages',
|
||||
staticDir: 'custom-static',
|
||||
css: [{ src: '~/custom-assets/app.css' }]
|
||||
css: [{ src: '~/custom-assets/app.css' }],
|
||||
dir: {
|
||||
assets: 'custom-assets',
|
||||
pages: 'custom-pages',
|
||||
static: 'custom-static'
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user