call .nuxt directory buildDir

This commit is contained in:
Mouti'a Benachour 2017-05-24 00:52:48 +01:00
parent b2ef8c320f
commit 923f907442
6 changed files with 17 additions and 15 deletions

View File

@ -112,10 +112,10 @@ export async function build () {
debug(`App root: ${this.srcDir}`)
debug('Generating .nuxt/ files...')
// Create .nuxt/, .nuxt/components and .nuxt/dist folders
await remove(r(this.dir, '.nuxt'))
await mkdirp(r(this.dir, '.nuxt/components'))
await remove(r(this.buildDir))
await mkdirp(r(this.buildDir, 'components'))
if (!this.dev) {
await mkdirp(r(this.dir, '.nuxt/dist'))
await mkdirp(r(this.buildDir, 'dist'))
}
// Generate routes and interpret the template files
await generateRoutesAndFiles.call(this)
@ -139,7 +139,7 @@ async function buildFiles () {
}
function addAppTemplate () {
let templatePath = resolve(this.dir, '.nuxt', 'dist', 'index.html')
let templatePath = resolve(this.buildDir, 'dist', 'index.html')
if (fs.existsSync(templatePath)) {
this.appTemplate = _.template(fs.readFileSync(templatePath, 'utf8'), {
interpolate: /{{([\s\S]+?)}}/g
@ -209,7 +209,7 @@ async function generateRoutesAndFiles () {
}
// If no default layout, create its folder and add the default folder
if (!templateVars.layouts.default) {
await mkdirp(r(this.dir, '.nuxt/layouts'))
await mkdirp(r(this.buildDir, 'layouts'))
templatesFiles.push('layouts/default.vue')
templateVars.layouts.default = r(__dirname, 'app', 'layouts', 'default.vue')
}
@ -284,7 +284,7 @@ async function generateRoutesAndFiles () {
src,
dst
}))
const path = r(this.dir, '.nuxt', dst)
const path = r(this.buildDir, dst)
// Ensure parent dir exits
await mkdirp(dirname(path))
// Write file

View File

@ -46,7 +46,7 @@ export default async function () {
*/
this.options.generate = _.defaultsDeep(this.options.generate, defaults)
var srcStaticPath = resolve(this.srcDir, 'static')
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
var srcBuiltPath = resolve(this.buildDir, 'dist')
var distPath = resolve(this.dir, this.options.generate.dir)
var distNuxtPath = join(distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
/*

View File

@ -74,11 +74,13 @@ class Nuxt {
this.options = _.defaultsDeep(options, defaults)
// Env variables
this.dev = this.options.dev
// Explicit srcDir and rootDir
// Explicit srcDir, rootDir and buildDir
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)
this.buildDir = resolve(this.dir, '.nuxt')
options.rootDir = this.dir
options.srcDir = this.srcDir
options.buildDir = this.buildDir
// If store defined, update store options to true
if (fs.existsSync(join(this.srcDir, 'store'))) {
this.options.store = true
@ -93,7 +95,7 @@ class Nuxt {
// For serving static/ files to /
this.serveStatic = pify(serveStatic(resolve(this.srcDir, 'static'), this.options.render.static))
// For serving .nuxt/dist/ files (only when build.publicPath is not an URL)
this.serveStaticNuxt = pify(serveStatic(resolve(this.dir, '.nuxt', 'dist'), {
this.serveStaticNuxt = pify(serveStatic(resolve(this.buildDir, 'dist'), {
maxAge: (this.dev ? 0 : '1y') // 1 year in production
}))
// gzip middleware for production

View File

@ -40,8 +40,8 @@ export default function ({ isClient, isServer }) {
'assets': join(this.srcDir, 'assets'), // use in template with <img src="~assets/nuxt.png" />
'~assets': join(this.srcDir, 'assets'),
'~plugins': join(this.srcDir, 'plugins'),
'~store': join(this.dir, '.nuxt/store'),
'~router': join(this.dir, '.nuxt/router'),
'~store': join(this.buildDir, 'store'),
'~router': join(this.buildDir, 'router'),
'~pages': join(this.srcDir, 'pages'),
'~components': join(this.srcDir, 'components')
},

View File

@ -25,7 +25,7 @@ export default function () {
let config = base.call(this, { isClient: true })
// Entry
config.entry.app = resolve(this.dir, '.nuxt', 'client.js')
config.entry.app = resolve(this.buildDir, 'client.js')
// Add vendors
if (this.options.store) {
@ -34,7 +34,7 @@ export default function () {
config.entry.vendor = config.entry.vendor.concat(this.options.build.vendor)
// Output
config.output.path = resolve(this.dir, '.nuxt', 'dist')
config.output.path = resolve(this.buildDir, 'dist')
config.output.filename = this.options.build.filenames.app
// env object defined in nuxt.config.js

View File

@ -24,9 +24,9 @@ export default function () {
config = Object.assign(config, {
target: 'node',
devtool: (this.dev ? 'source-map' : false),
entry: resolve(this.dir, '.nuxt', 'server.js'),
entry: resolve(this.buildDir, 'server.js'),
output: Object.assign({}, config.output, {
path: resolve(this.dir, '.nuxt', 'dist'),
path: resolve(this.buildDir, 'dist'),
filename: 'server-bundle.js',
libraryTarget: 'commonjs2'
}),