From be4d8c5e134b50e5f9655c7276b1e84550e5e911 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 30 Jul 2017 16:50:58 +0430 Subject: [PATCH] internal refactors --- lib/builder/index.js | 5 +++++ lib/common/index.js | 9 ++++++++- lib/{core => common}/options.js | 10 +++++----- lib/core/index.js | 17 ++++++++++++----- lib/core/nuxt.js | 2 +- lib/core/renderer.js | 4 ++-- 6 files changed, 33 insertions(+), 14 deletions(-) rename lib/{core => common}/options.js (96%) diff --git a/lib/builder/index.js b/lib/builder/index.js index 34547d0c2a..2f96f7f4e8 100755 --- a/lib/builder/index.js +++ b/lib/builder/index.js @@ -5,3 +5,8 @@ export default { Builder, Generator } + +export { + Builder, + Generator +} diff --git a/lib/common/index.js b/lib/common/index.js index 46498a8c10..26a5ba474a 100755 --- a/lib/common/index.js +++ b/lib/common/index.js @@ -1,5 +1,12 @@ import * as Utils from './utils' +import Options from './options' export default { - Utils + Utils, + Options +} + +export { + Utils, + Options } diff --git a/lib/core/options.js b/lib/common/options.js similarity index 96% rename from lib/core/options.js rename to lib/common/options.js index 2d58aabd3a..71b55dabcc 100755 --- a/lib/core/options.js +++ b/lib/common/options.js @@ -22,7 +22,7 @@ export default function Options (_options) { } // Apply defaults - _.defaultsDeep(options, defaultOptions) + _.defaultsDeep(options, Options.defaults) // Resolve dirs options.rootDir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd()) @@ -38,7 +38,7 @@ export default function Options (_options) { // Ignore publicPath on dev /* istanbul ignore if */ if (options.dev && isUrl(options.build.publicPath)) { - options.build.publicPath = defaultOptions.build.publicPath + options.build.publicPath = Options.defaults.build.publicPath } // If store defined, update store options to true unless explicitly disabled @@ -52,7 +52,7 @@ export default function Options (_options) { mode = mode() } if (typeof mode === 'string') { - mode = Modes[mode] + mode = Options.modes[mode] } // Apply mode @@ -61,7 +61,7 @@ export default function Options (_options) { return options } -const Modes = { +Options.modes = { universal: { build: { ssr: true @@ -88,7 +88,7 @@ const Modes = { } } -export const defaultOptions = { +Options.defaults = { mode: 'universal', dev: process.env.NODE_ENV !== 'production', buildDir: '.nuxt', diff --git a/lib/core/index.js b/lib/core/index.js index 4bf8a61bf0..2af3372c2d 100755 --- a/lib/core/index.js +++ b/lib/core/index.js @@ -1,13 +1,20 @@ -import Options from './options' -import ModuleContainer from './module' +import { Options, Utils } from 'common' +import Module from './module' import Nuxt from './nuxt' import Renderer from './renderer' -import * as Utils from 'utils' export default { - Options, - ModuleContainer, Nuxt, + Module, Renderer, + Options, + Utils +} + +export { + Nuxt, + Module, + Renderer, + Options, Utils } diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index 156edcfeeb..7ef1bd4482 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -1,8 +1,8 @@ import Tapable from 'tappable' import chalk from 'chalk' +import { Options } from 'common' import ModuleContainer from './module' import Renderer from './renderer' -import Options from './options' import Debug from 'debug' import enableDestroy from 'server-destroy' import Module from 'module' diff --git a/lib/core/renderer.js b/lib/core/renderer.js index a35fc8adf3..874b2339da 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -11,9 +11,9 @@ import { join, resolve } from 'path' import fs from 'fs-extra' import { createBundleRenderer } from 'vue-server-renderer' import { encodeHtml, getContext, setAnsiColors, isUrl } from 'utils' -import { defaultOptions } from './options' import Debug from 'debug' import connect from 'connect' +import { Options } from 'common' const debug = Debug('nuxt:render') debug.color = 4 // Force blue color @@ -196,7 +196,7 @@ export default class Renderer extends Tapable { if (!this.options.dev) { const distDir = resolve(this.options.buildDir, 'dist') this.useMiddleware({ - path: isUrl(this.options.build.publicPath) ? defaultOptions.build.publicPath : this.options.build.publicPath, + path: isUrl(this.options.build.publicPath) ? Options.defaults.build.publicPath : this.options.build.publicPath, handler: serveStatic(distDir, { index: false, // Don't serve index.html template maxAge: (this.options.dev ? 0 : '1y') // 1 year in production