2017-12-12 09:42:29 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const Debug = require('debug')
|
|
|
|
const { join, resolve } = require('path')
|
|
|
|
const { existsSync } = require('fs')
|
|
|
|
const { isUrl, isPureObject } = require('../common/utils')
|
2017-06-14 16:13:43 +00:00
|
|
|
|
2017-11-03 11:31:12 +00:00
|
|
|
const debug = Debug('nuxt:build')
|
|
|
|
debug.color = 2 // Force green color
|
|
|
|
|
2017-08-16 07:40:10 +00:00
|
|
|
const Options = {}
|
|
|
|
|
2017-12-12 09:42:29 +00:00
|
|
|
module.exports = Options
|
2017-08-16 07:40:10 +00:00
|
|
|
|
|
|
|
Options.from = function (_options) {
|
2017-06-14 16:13:43 +00:00
|
|
|
// Clone options to prevent unwanted side-effects
|
|
|
|
const options = Object.assign({}, _options)
|
|
|
|
|
|
|
|
// Normalize options
|
|
|
|
if (options.loading === true) {
|
|
|
|
delete options.loading
|
|
|
|
}
|
2018-01-13 05:22:11 +00:00
|
|
|
if (
|
|
|
|
options.router &&
|
|
|
|
options.router.middleware &&
|
|
|
|
!Array.isArray(options.router.middleware)
|
|
|
|
) {
|
2017-06-14 16:13:43 +00:00
|
|
|
options.router.middleware = [options.router.middleware]
|
|
|
|
}
|
|
|
|
if (options.router && typeof options.router.base === 'string') {
|
|
|
|
options._routerBaseSpecified = true
|
|
|
|
}
|
|
|
|
if (typeof options.transition === 'string') {
|
|
|
|
options.transition = { name: options.transition }
|
|
|
|
}
|
2017-09-08 10:42:00 +00:00
|
|
|
if (typeof options.layoutTransition === 'string') {
|
|
|
|
options.layoutTransition = { name: options.layoutTransition }
|
|
|
|
}
|
2018-01-04 17:10:17 +00:00
|
|
|
if (typeof options.extensions === 'string') {
|
2018-01-13 05:22:11 +00:00
|
|
|
options.extensions = [options.extensions]
|
2018-01-04 17:10:17 +00:00
|
|
|
}
|
2017-06-14 16:13:43 +00:00
|
|
|
|
2017-12-04 19:52:50 +00:00
|
|
|
const hasValue = v => typeof v === 'string' && v
|
|
|
|
options.rootDir = hasValue(options.rootDir) ? options.rootDir : process.cwd()
|
|
|
|
|
|
|
|
// Apply defaults by ${buildDir}/dist/build.config.js
|
2017-12-13 02:17:44 +00:00
|
|
|
// TODO: Unsafe operation.
|
|
|
|
// const buildDir = options.buildDir || Options.defaults.buildDir
|
|
|
|
// const buildConfig = resolve(options.rootDir, buildDir, 'build.config.js')
|
|
|
|
// if (existsSync(buildConfig)) {
|
|
|
|
// _.defaultsDeep(options, require(buildConfig))
|
|
|
|
// }
|
|
|
|
|
2017-06-14 16:13:43 +00:00
|
|
|
// Apply defaults
|
2017-07-30 12:20:58 +00:00
|
|
|
_.defaultsDeep(options, Options.defaults)
|
2017-06-14 16:13:43 +00:00
|
|
|
|
|
|
|
// Resolve dirs
|
2018-01-13 05:22:11 +00:00
|
|
|
options.srcDir = hasValue(options.srcDir)
|
|
|
|
? resolve(options.rootDir, options.srcDir)
|
|
|
|
: options.rootDir
|
2017-08-21 11:16:35 +00:00
|
|
|
options.buildDir = resolve(options.rootDir, options.buildDir)
|
|
|
|
options.cacheDir = resolve(options.rootDir, options.cacheDir)
|
2017-06-14 16:13:43 +00:00
|
|
|
|
2017-12-13 01:09:38 +00:00
|
|
|
// Populate modulesDir
|
|
|
|
options.modulesDir = []
|
2017-12-28 16:49:56 +00:00
|
|
|
.concat(options.modulesDir)
|
2018-01-11 11:53:55 +00:00
|
|
|
.concat(join(options.nuxtDir, 'node_modules'))
|
2017-12-13 01:09:38 +00:00
|
|
|
.filter(dir => hasValue(dir))
|
|
|
|
.map(dir => resolve(options.rootDir, dir))
|
2017-12-12 12:57:01 +00:00
|
|
|
|
2018-01-04 17:10:17 +00:00
|
|
|
// Sanitize extensions
|
|
|
|
if (options.extensions.indexOf('js') === -1) {
|
|
|
|
options.extensions.unshift('js')
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:13:43 +00:00
|
|
|
// If app.html is defined, set the template path to the user template
|
2017-06-16 12:42:45 +00:00
|
|
|
options.appTemplatePath = resolve(options.buildDir, 'views/app.template.html')
|
2017-06-14 16:13:43 +00:00
|
|
|
if (existsSync(join(options.srcDir, 'app.html'))) {
|
|
|
|
options.appTemplatePath = join(options.srcDir, 'app.html')
|
|
|
|
}
|
|
|
|
|
2017-06-14 17:32:25 +00:00
|
|
|
// Ignore publicPath on dev
|
2017-06-19 15:47:31 +00:00
|
|
|
/* istanbul ignore if */
|
2017-06-14 17:32:25 +00:00
|
|
|
if (options.dev && isUrl(options.build.publicPath)) {
|
2017-07-30 12:20:58 +00:00
|
|
|
options.build.publicPath = Options.defaults.build.publicPath
|
2017-06-14 17:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If store defined, update store options to true unless explicitly disabled
|
|
|
|
if (options.store !== false && existsSync(join(options.srcDir, 'store'))) {
|
2017-06-14 17:38:07 +00:00
|
|
|
options.store = true
|
2017-06-14 17:32:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 10:26:19 +00:00
|
|
|
// Normalize loadingIndicator
|
|
|
|
if (!isPureObject(options.loadingIndicator)) {
|
|
|
|
options.loadingIndicator = { name: options.loadingIndicator }
|
|
|
|
}
|
2018-01-10 16:36:32 +00:00
|
|
|
|
2018-01-10 16:31:27 +00:00
|
|
|
// Apply default hash to CSP option
|
|
|
|
if (options.render.csp === true) {
|
|
|
|
options.render.csp = { hashAlgorithm: 'sha256' }
|
|
|
|
}
|
2017-08-18 10:26:19 +00:00
|
|
|
|
|
|
|
// Apply defaults to loadingIndicator
|
2018-01-13 05:22:11 +00:00
|
|
|
options.loadingIndicator = Object.assign(
|
|
|
|
{
|
|
|
|
name: 'pulse',
|
|
|
|
color: '#dbe1ec',
|
|
|
|
background: 'white'
|
|
|
|
},
|
|
|
|
options.loadingIndicator
|
|
|
|
)
|
2017-08-18 10:26:19 +00:00
|
|
|
|
2017-08-20 08:38:38 +00:00
|
|
|
// cssSourceMap
|
|
|
|
if (options.build.cssSourceMap === undefined) {
|
|
|
|
options.build.cssSourceMap = options.dev
|
|
|
|
}
|
|
|
|
|
2017-08-05 00:58:26 +00:00
|
|
|
// Debug errors
|
2017-08-05 21:48:43 +00:00
|
|
|
if (options.debug === undefined) {
|
|
|
|
options.debug = options.dev
|
2017-08-05 00:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 09:44:44 +00:00
|
|
|
// Normalize ignore
|
|
|
|
options.ignore = options.ignore ? [].concat(options.ignore) : []
|
|
|
|
|
|
|
|
// Append ignorePrefix glob to ignore
|
|
|
|
if (typeof options.ignorePrefix === 'string') {
|
|
|
|
options.ignore.push(`**/${options.ignorePrefix}*.*`)
|
|
|
|
}
|
|
|
|
|
2017-08-19 13:22:53 +00:00
|
|
|
// Apply mode preset
|
2018-01-13 05:22:11 +00:00
|
|
|
let modePreset =
|
|
|
|
Options.modes[options.mode || 'universal'] || Options.modes['universal']
|
2017-08-19 13:22:53 +00:00
|
|
|
_.defaultsDeep(options, modePreset)
|
2017-07-11 00:24:39 +00:00
|
|
|
|
2017-08-18 13:44:34 +00:00
|
|
|
// If no server-side rendering, add appear true transition
|
2017-11-24 15:44:07 +00:00
|
|
|
/* istanbul ignore if */
|
2017-11-16 10:56:41 +00:00
|
|
|
if (options.render.ssr === false && options.transition) {
|
2017-08-18 13:44:34 +00:00
|
|
|
options.transition.appear = true
|
|
|
|
}
|
|
|
|
|
2018-01-27 00:20:03 +00:00
|
|
|
// We assume the SPA fallback path is 404.html (for GitHub Pages, Surge, etc.)
|
|
|
|
if (options.generate.fallback === true) {
|
|
|
|
options.generate.fallback = '404.html'
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:13:43 +00:00
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
2017-07-30 12:20:58 +00:00
|
|
|
Options.modes = {
|
2017-07-11 00:24:39 +00:00
|
|
|
universal: {
|
|
|
|
build: {
|
|
|
|
ssr: true
|
|
|
|
},
|
|
|
|
render: {
|
|
|
|
ssr: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
spa: {
|
|
|
|
build: {
|
|
|
|
ssr: false
|
|
|
|
},
|
|
|
|
render: {
|
|
|
|
ssr: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 15:11:03 +00:00
|
|
|
// Options.unsafeKeys = [
|
|
|
|
// 'rootDir', 'srcDir', 'buildDir', 'modulesDir', 'cacheDir', 'nuxtDir',
|
|
|
|
// 'nuxtAppDir', 'build', 'generate', 'router.routes', 'appTemplatePath'
|
|
|
|
// ]
|
2017-12-04 19:52:50 +00:00
|
|
|
|
2017-07-30 12:20:58 +00:00
|
|
|
Options.defaults = {
|
2017-07-11 00:24:39 +00:00
|
|
|
mode: 'universal',
|
|
|
|
dev: process.env.NODE_ENV !== 'production',
|
2017-08-05 21:48:43 +00:00
|
|
|
debug: undefined, // Will be equal to dev if not provided
|
2017-06-11 14:17:36 +00:00
|
|
|
buildDir: '.nuxt',
|
2017-08-21 11:16:35 +00:00
|
|
|
cacheDir: '.cache',
|
2017-12-12 09:42:29 +00:00
|
|
|
nuxtDir: resolve(__dirname, '../..'),
|
|
|
|
nuxtAppDir: resolve(__dirname, '../app'),
|
2017-12-13 01:09:38 +00:00
|
|
|
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
2017-12-18 15:53:36 +00:00
|
|
|
ignorePrefix: '-',
|
2018-01-15 09:44:44 +00:00
|
|
|
ignore: [
|
|
|
|
'**/*.test.*'
|
|
|
|
],
|
2018-01-04 17:10:17 +00:00
|
|
|
extensions: [],
|
2017-06-11 14:17:36 +00:00
|
|
|
build: {
|
|
|
|
analyze: false,
|
2017-12-12 11:46:19 +00:00
|
|
|
profile: process.argv.includes('--profile'),
|
2017-08-21 11:16:35 +00:00
|
|
|
dll: false,
|
2017-11-07 12:05:41 +00:00
|
|
|
scopeHoisting: false,
|
2018-01-25 08:01:48 +00:00
|
|
|
maxChunkSize: false,
|
2017-06-11 14:17:36 +00:00
|
|
|
extractCSS: false,
|
2017-08-19 12:10:55 +00:00
|
|
|
cssSourceMap: undefined,
|
2017-07-11 00:24:39 +00:00
|
|
|
ssr: undefined,
|
2017-11-24 15:32:05 +00:00
|
|
|
uglify: {},
|
2017-06-11 14:17:36 +00:00
|
|
|
publicPath: '/_nuxt/',
|
|
|
|
filenames: {
|
2018-01-04 23:34:20 +00:00
|
|
|
css: '[name].[contenthash].css',
|
2017-06-11 14:17:36 +00:00
|
|
|
manifest: 'manifest.[hash].js',
|
2017-11-07 12:05:41 +00:00
|
|
|
vendor: 'vendor.[chunkhash].js',
|
2018-01-16 06:55:23 +00:00
|
|
|
app: '[name].[chunkhash].js',
|
2017-08-16 10:36:27 +00:00
|
|
|
chunk: '[name].[chunkhash].js'
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
2018-01-08 09:37:10 +00:00
|
|
|
styleResources: {},
|
2017-06-11 14:17:36 +00:00
|
|
|
vendor: [],
|
|
|
|
plugins: [],
|
|
|
|
babel: {},
|
2017-08-15 01:06:56 +00:00
|
|
|
postcss: {},
|
2017-06-11 14:17:36 +00:00
|
|
|
templates: [],
|
2017-07-09 09:40:37 +00:00
|
|
|
watch: [],
|
|
|
|
devMiddleware: {},
|
2017-12-17 13:59:50 +00:00
|
|
|
hotMiddleware: {},
|
|
|
|
stats: {
|
|
|
|
chunks: false,
|
|
|
|
children: false,
|
|
|
|
modules: false,
|
|
|
|
colors: true,
|
|
|
|
excludeAssets: [
|
|
|
|
/.map$/,
|
|
|
|
/index\..+\.html$/,
|
|
|
|
/vue-ssr-client-manifest.json/
|
|
|
|
]
|
|
|
|
}
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
|
|
|
generate: {
|
|
|
|
dir: 'dist',
|
|
|
|
routes: [],
|
2017-07-09 10:00:08 +00:00
|
|
|
concurrency: 500,
|
2017-06-11 14:17:36 +00:00
|
|
|
interval: 0,
|
2017-11-06 07:36:28 +00:00
|
|
|
subFolders: true,
|
2018-01-27 00:20:03 +00:00
|
|
|
fallback: '200.html',
|
2017-06-11 14:17:36 +00:00
|
|
|
minify: {
|
|
|
|
collapseBooleanAttributes: true,
|
2017-11-03 15:00:09 +00:00
|
|
|
collapseWhitespace: false,
|
2017-06-11 14:17:36 +00:00
|
|
|
decodeEntities: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
minifyJS: true,
|
|
|
|
processConditionalComments: true,
|
|
|
|
removeAttributeQuotes: false,
|
|
|
|
removeComments: false,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeOptionalTags: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: false,
|
|
|
|
removeStyleLinkTypeAttributes: false,
|
|
|
|
removeTagWhitespace: false,
|
|
|
|
sortAttributes: true,
|
2017-08-13 19:12:35 +00:00
|
|
|
sortClassName: false,
|
2017-06-11 14:17:36 +00:00
|
|
|
trimCustomFragments: true,
|
|
|
|
useShortDoctype: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
env: {},
|
|
|
|
head: {
|
|
|
|
meta: [],
|
|
|
|
link: [],
|
|
|
|
style: [],
|
|
|
|
script: []
|
|
|
|
},
|
|
|
|
plugins: [],
|
|
|
|
css: [],
|
|
|
|
modules: [],
|
|
|
|
layouts: {},
|
|
|
|
serverMiddleware: [],
|
|
|
|
ErrorPage: null,
|
|
|
|
loading: {
|
|
|
|
color: 'black',
|
|
|
|
failedColor: 'red',
|
|
|
|
height: '2px',
|
2017-08-29 11:58:45 +00:00
|
|
|
duration: 5000,
|
|
|
|
rtl: false
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
2017-08-18 10:29:37 +00:00
|
|
|
loadingIndicator: {},
|
2017-06-11 14:17:36 +00:00
|
|
|
transition: {
|
|
|
|
name: 'page',
|
2017-08-18 13:44:34 +00:00
|
|
|
mode: 'out-in',
|
2017-08-18 14:47:01 +00:00
|
|
|
appear: false,
|
|
|
|
appearClass: 'appear',
|
|
|
|
appearActiveClass: 'appear-active',
|
|
|
|
appearToClass: 'appear-to'
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
2017-09-08 10:42:00 +00:00
|
|
|
layoutTransition: {
|
|
|
|
name: 'layout',
|
|
|
|
mode: 'out-in'
|
|
|
|
},
|
2017-06-11 14:17:36 +00:00
|
|
|
router: {
|
|
|
|
mode: 'history',
|
|
|
|
base: '/',
|
2017-06-13 17:58:04 +00:00
|
|
|
routes: [],
|
2017-06-11 14:17:36 +00:00
|
|
|
middleware: [],
|
|
|
|
linkActiveClass: 'nuxt-link-active',
|
|
|
|
linkExactActiveClass: 'nuxt-link-exact-active',
|
|
|
|
extendRoutes: null,
|
2017-07-04 16:30:01 +00:00
|
|
|
scrollBehavior: null,
|
2017-11-14 03:06:06 +00:00
|
|
|
parseQuery: false,
|
|
|
|
stringifyQuery: false,
|
2017-07-04 16:30:01 +00:00
|
|
|
fallback: false
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
|
|
|
render: {
|
2017-07-04 21:50:43 +00:00
|
|
|
bundleRenderer: {},
|
2017-06-20 12:48:25 +00:00
|
|
|
resourceHints: true,
|
2017-07-11 00:24:39 +00:00
|
|
|
ssr: undefined,
|
2017-06-11 14:17:36 +00:00
|
|
|
http2: {
|
2018-01-04 22:10:52 +00:00
|
|
|
push: false,
|
|
|
|
shouldPush: null
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
2018-02-05 01:36:45 +00:00
|
|
|
static: {
|
|
|
|
prefix: true
|
|
|
|
},
|
2017-06-11 14:17:36 +00:00
|
|
|
gzip: {
|
|
|
|
threshold: 0
|
|
|
|
},
|
|
|
|
etag: {
|
2018-01-04 22:13:59 +00:00
|
|
|
weak: false
|
2018-01-10 06:36:34 +00:00
|
|
|
},
|
2018-01-16 15:10:10 +00:00
|
|
|
csp: {
|
2018-01-16 15:11:17 +00:00
|
|
|
enabled: false,
|
|
|
|
hashAlgorithm: 'sha256',
|
2018-02-01 12:20:28 +00:00
|
|
|
allowedSources: undefined,
|
|
|
|
policies: undefined
|
2018-01-16 15:10:10 +00:00
|
|
|
}
|
2017-06-11 14:17:36 +00:00
|
|
|
},
|
|
|
|
watchers: {
|
2017-08-21 11:16:35 +00:00
|
|
|
webpack: {
|
|
|
|
ignored: /-dll/
|
|
|
|
},
|
2017-06-11 14:17:36 +00:00
|
|
|
chokidar: {}
|
2017-09-01 16:16:08 +00:00
|
|
|
},
|
2018-01-06 19:57:20 +00:00
|
|
|
editor: undefined,
|
2017-10-31 11:33:15 +00:00
|
|
|
hooks: null,
|
2017-09-01 16:16:08 +00:00
|
|
|
messages: {
|
2017-09-01 16:40:01 +00:00
|
|
|
error_404: 'This page could not be found',
|
2017-09-01 16:30:49 +00:00
|
|
|
server_error: 'Server error',
|
|
|
|
nuxtjs: 'Nuxt.js',
|
|
|
|
back_to_home: 'Back to the home page',
|
2018-01-13 05:22:11 +00:00
|
|
|
server_error_details:
|
|
|
|
'An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.',
|
2017-09-01 16:30:49 +00:00
|
|
|
client_error: 'Error',
|
2018-01-13 05:22:11 +00:00
|
|
|
client_error_details:
|
2018-01-15 11:22:51 +00:00
|
|
|
'An error occurred while rendering the page. Check developer tools console for details.'
|
2017-06-11 14:17:36 +00:00
|
|
|
}
|
|
|
|
}
|