mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
commit
e254e11177
@ -91,15 +91,15 @@ exports.build = function * () {
|
|||||||
/*
|
/*
|
||||||
** Check if pages dir exists and warn if not
|
** Check if pages dir exists and warn if not
|
||||||
*/
|
*/
|
||||||
if (!fs.existsSync(join(this.dir, 'pages'))) {
|
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
||||||
if (fs.existsSync(join(this.dir, '..', 'pages'))) {
|
if (fs.existsSync(join(this.srcDir, '..', 'pages'))) {
|
||||||
console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console
|
console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console
|
||||||
} else {
|
} else {
|
||||||
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
debug(`App root: ${this.dir}`)
|
debug(`App root: ${this.srcDir}`)
|
||||||
debug('Generating .nuxt/ files...')
|
debug('Generating .nuxt/ files...')
|
||||||
/*
|
/*
|
||||||
** Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
** Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
||||||
@ -114,7 +114,7 @@ exports.build = function * () {
|
|||||||
if (route.component.slice(-4) !== '.vue') {
|
if (route.component.slice(-4) !== '.vue') {
|
||||||
route.component = route.component + '.vue'
|
route.component = route.component + '.vue'
|
||||||
}
|
}
|
||||||
route.component = r(this.dir, route.component)
|
route.component = r(this.srcDir, route.component)
|
||||||
})
|
})
|
||||||
// Generate routes and interpret the template files
|
// Generate routes and interpret the template files
|
||||||
yield generateRoutesAndFiles.call(this)
|
yield generateRoutesAndFiles.call(this)
|
||||||
@ -141,13 +141,13 @@ function * generateRoutesAndFiles () {
|
|||||||
/*
|
/*
|
||||||
** Generate routes based on files
|
** Generate routes based on files
|
||||||
*/
|
*/
|
||||||
const files = yield glob('pages/**/*.vue', { cwd: this.dir })
|
const files = yield glob('pages/**/*.vue', { cwd: this.srcDir })
|
||||||
let routes = []
|
let routes = []
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
let path = file.replace(/^pages/, '').replace(/index\.vue$/, '/').replace(/\.vue$/, '').replace(/\/{2,}/g, '/')
|
let path = file.replace(/^pages/, '').replace(/index\.vue$/, '/').replace(/\.vue$/, '').replace(/\/{2,}/g, '/')
|
||||||
let name = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1).join('-')
|
let name = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1).join('-')
|
||||||
if (basename(path)[0] === '_') return
|
if (basename(path)[0] === '_') return
|
||||||
routes.push({ path: path, component: r(this.dir, file), name: name })
|
routes.push({ path: path, component: r(this.srcDir, file), name: name })
|
||||||
})
|
})
|
||||||
// Concat pages routes and custom routes in this.routes
|
// Concat pages routes and custom routes in this.routes
|
||||||
this.routes = routes.concat(this.options.router.routes)
|
this.routes = routes.concat(this.options.router.routes)
|
||||||
@ -177,9 +177,9 @@ function * generateRoutesAndFiles () {
|
|||||||
head: this.options.head,
|
head: this.options.head,
|
||||||
store: this.options.store,
|
store: this.options.store,
|
||||||
css: this.options.css,
|
css: this.options.css,
|
||||||
plugins: this.options.plugins.map((p) => r(this.dir, p)),
|
plugins: this.options.plugins.map((p) => r(this.srcDir, p)),
|
||||||
appPath: './App.vue',
|
appPath: './App.vue',
|
||||||
loading: (typeof this.options.loading === 'string' ? r(this.dir, this.options.loading) : this.options.loading),
|
loading: (typeof this.options.loading === 'string' ? r(this.srcDir, this.options.loading) : this.options.loading),
|
||||||
transition: this.options.transition,
|
transition: this.options.transition,
|
||||||
components: {
|
components: {
|
||||||
Loading: r(__dirname, '..', 'app', 'components', 'nuxt-loading.vue'),
|
Loading: r(__dirname, '..', 'app', 'components', 'nuxt-loading.vue'),
|
||||||
@ -199,15 +199,15 @@ function * generateRoutesAndFiles () {
|
|||||||
return r
|
return r
|
||||||
})
|
})
|
||||||
if (files.includes('pages/_app.vue')) {
|
if (files.includes('pages/_app.vue')) {
|
||||||
templateVars.appPath = r(this.dir, 'pages/_app.vue')
|
templateVars.appPath = r(this.srcDir, 'pages/_app.vue')
|
||||||
}
|
}
|
||||||
if (fs.existsSync(join(this.dir, 'layouts', 'app.vue'))) {
|
if (fs.existsSync(join(this.srcDir, 'layouts', 'app.vue'))) {
|
||||||
templateVars.appPath = r(this.dir, 'layouts/app.vue')
|
templateVars.appPath = r(this.srcDir, 'layouts/app.vue')
|
||||||
}
|
}
|
||||||
if (files.includes('pages/_error.vue')) {
|
if (files.includes('pages/_error.vue')) {
|
||||||
templateVars.components.ErrorPage = r(this.dir, 'pages/_error.vue')
|
templateVars.components.ErrorPage = r(this.srcDir, 'pages/_error.vue')
|
||||||
}
|
}
|
||||||
if (fs.existsSync(join(this.dir, 'layouts', 'error.vue'))) {
|
if (fs.existsSync(join(this.srcDir, 'layouts', 'error.vue'))) {
|
||||||
templateVars.components.ErrorPage = r(this.dir, 'layouts/error.vue')
|
templateVars.components.ErrorPage = r(this.dir, 'layouts/error.vue')
|
||||||
}
|
}
|
||||||
let moveTemplates = templatesFiles.map((file) => {
|
let moveTemplates = templatesFiles.map((file) => {
|
||||||
@ -316,7 +316,7 @@ function createRenderer (bundle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function watchPages () {
|
function watchPages () {
|
||||||
const patterns = [ r(this.dir, 'pages/*.vue'), r(this.dir, 'pages/**/*.vue') ]
|
const patterns = [ r(this.srcDir, 'pages/*.vue'), r(this.srcDir, 'pages/**/*.vue') ]
|
||||||
const options = {
|
const options = {
|
||||||
// ignored: '**/_*.vue',
|
// ignored: '**/_*.vue',
|
||||||
ignoreInitial: true
|
ignoreInitial: true
|
||||||
|
@ -26,16 +26,16 @@ module.exports = function () {
|
|||||||
resolve: {
|
resolve: {
|
||||||
// Disable for now
|
// Disable for now
|
||||||
alias: {
|
alias: {
|
||||||
'~': join(this.dir),
|
'~': join(this.srcDir),
|
||||||
'static': join(this.dir, 'static'), // use in template with <img src="~static/nuxt.png" />
|
'static': join(this.srcDir, 'static'), // use in template with <img src="~static/nuxt.png" />
|
||||||
'~static': join(this.dir, 'static'),
|
'~static': join(this.srcDir, 'static'),
|
||||||
'assets': join(this.dir, 'assets'), // use in template with <img src="~static/nuxt.png" />
|
'assets': join(this.srcDir, 'assets'), // use in template with <img src="~static/nuxt.png" />
|
||||||
'~assets': join(this.dir, 'assets'),
|
'~assets': join(this.srcDir, 'assets'),
|
||||||
'~plugins': join(this.dir, 'plugins'),
|
'~plugins': join(this.srcDir, 'plugins'),
|
||||||
'~store': join(this.dir, 'store'),
|
'~store': join(this.srcDir, 'store'),
|
||||||
'~router': join(this.dir, '.nuxt/router'),
|
'~router': join(this.dir, '.nuxt/router'),
|
||||||
'~pages': join(this.dir, 'pages'),
|
'~pages': join(this.srcDir, 'pages'),
|
||||||
'~components': join(this.dir, 'components')
|
'~components': join(this.srcDir, 'components')
|
||||||
},
|
},
|
||||||
modules: [
|
modules: [
|
||||||
nodeModulesDir,
|
nodeModulesDir,
|
||||||
|
@ -34,7 +34,7 @@ module.exports = function () {
|
|||||||
*/
|
*/
|
||||||
this.options.generate = _.defaultsDeep(this.options.generate, defaults)
|
this.options.generate = _.defaultsDeep(this.options.generate, defaults)
|
||||||
var self = this
|
var self = this
|
||||||
var srcStaticPath = resolve(this.dir, 'static')
|
var srcStaticPath = resolve(this.srcDir, 'static')
|
||||||
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
|
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
|
||||||
var distPath = resolve(this.dir, this.options.generate.dir)
|
var distPath = resolve(this.dir, this.options.generate.dir)
|
||||||
var distNuxtPath = resolve(distPath, '_nuxt')
|
var distNuxtPath = resolve(distPath, '_nuxt')
|
||||||
|
@ -51,8 +51,9 @@ class Nuxt {
|
|||||||
// Env variables
|
// Env variables
|
||||||
this.dev = this.options.dev
|
this.dev = this.options.dev
|
||||||
this.dir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd())
|
this.dir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd())
|
||||||
|
this.srcDir = (typeof options.srcDir === 'string' && options.srcDir ? resolve(this.dir, options.srcDir) : this.dir)
|
||||||
// If store defined, update store options to true
|
// If store defined, update store options to true
|
||||||
if (fs.existsSync(join(this.dir, 'store', 'index.js'))) {
|
if (fs.existsSync(join(this.srcDir, 'store', 'index.js'))) {
|
||||||
this.options.store = true
|
this.options.store = true
|
||||||
}
|
}
|
||||||
// Template
|
// Template
|
||||||
@ -65,7 +66,7 @@ class Nuxt {
|
|||||||
// renderer used by Vue.js (via createBundleRenderer)
|
// renderer used by Vue.js (via createBundleRenderer)
|
||||||
this.renderer = null
|
this.renderer = null
|
||||||
// For serving static/ files to /
|
// For serving static/ files to /
|
||||||
this.serveStatic = pify(serveStatic(resolve(this.dir, 'static')))
|
this.serveStatic = pify(serveStatic(resolve(this.srcDir, 'static')))
|
||||||
// For serving .nuxt/dist/ files
|
// For serving .nuxt/dist/ files
|
||||||
this._nuxtRegexp = /^\/_nuxt\//
|
this._nuxtRegexp = /^\/_nuxt\//
|
||||||
this.serveStaticNuxt = pify(serveStatic(resolve(this.dir, '.nuxt', 'dist')))
|
this.serveStaticNuxt = pify(serveStatic(resolve(this.dir, '.nuxt', 'dist')))
|
||||||
|
Loading…
Reference in New Issue
Block a user