mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
refactor options
This commit is contained in:
parent
f20ad95b2b
commit
ec616f109b
18
lib/common/modes.js
Normal file
18
lib/common/modes.js
Normal file
@ -0,0 +1,18 @@
|
||||
export default {
|
||||
universal: {
|
||||
build: {
|
||||
ssr: true
|
||||
},
|
||||
render: {
|
||||
ssr: true
|
||||
}
|
||||
},
|
||||
spa: {
|
||||
build: {
|
||||
ssr: false
|
||||
},
|
||||
render: {
|
||||
ssr: false
|
||||
}
|
||||
}
|
||||
}
|
177
lib/common/nuxt.config.js
Normal file
177
lib/common/nuxt.config.js
Normal file
@ -0,0 +1,177 @@
|
||||
import { resolve } from 'path'
|
||||
|
||||
export default {
|
||||
mode: 'universal',
|
||||
dev: process.env.NODE_ENV !== 'production',
|
||||
debug: undefined, // Will be equal to dev if not provided
|
||||
buildDir: '.nuxt',
|
||||
cacheDir: '.cache',
|
||||
nuxtDir: resolve(__dirname, '../..'),
|
||||
nuxtAppDir: resolve(__dirname, '../app'),
|
||||
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
||||
ignorePrefix: '-',
|
||||
ignore: [
|
||||
'**/*.test.*'
|
||||
],
|
||||
extensions: [],
|
||||
build: {
|
||||
analyze: false,
|
||||
profile: process.argv.includes('--profile'),
|
||||
splitPages: true,
|
||||
maxChunkSize: false,
|
||||
extractCSS: false,
|
||||
cssSourceMap: undefined,
|
||||
ssr: undefined,
|
||||
publicPath: '/_nuxt/',
|
||||
filenames: {
|
||||
css: '[name].[contenthash].css',
|
||||
manifest: 'manifest.[hash].js',
|
||||
app: '[name].[chunkhash].js',
|
||||
chunk: '[name].[chunkhash].js'
|
||||
},
|
||||
styleResources: {},
|
||||
plugins: [],
|
||||
babel: {
|
||||
babelrc: false
|
||||
},
|
||||
postcss: {},
|
||||
templates: [],
|
||||
watch: [],
|
||||
devMiddleware: {},
|
||||
hotMiddleware: {},
|
||||
stats: {
|
||||
chunks: false,
|
||||
children: false,
|
||||
modules: false,
|
||||
colors: true,
|
||||
excludeAssets: [
|
||||
/.map$/,
|
||||
/index\..+\.html$/,
|
||||
/vue-ssr-client-manifest.json/
|
||||
]
|
||||
}
|
||||
},
|
||||
generate: {
|
||||
dir: 'dist',
|
||||
routes: [],
|
||||
concurrency: 500,
|
||||
interval: 0,
|
||||
subFolders: true,
|
||||
fallback: '200.html',
|
||||
minify: {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: false,
|
||||
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,
|
||||
sortClassName: false,
|
||||
trimCustomFragments: true,
|
||||
useShortDoctype: true
|
||||
}
|
||||
},
|
||||
env: {},
|
||||
head: {
|
||||
meta: [],
|
||||
link: [],
|
||||
style: [],
|
||||
script: []
|
||||
},
|
||||
plugins: [],
|
||||
css: [],
|
||||
modules: [],
|
||||
layouts: {},
|
||||
serverMiddleware: [],
|
||||
ErrorPage: null,
|
||||
loading: {
|
||||
color: 'black',
|
||||
failedColor: 'red',
|
||||
height: '2px',
|
||||
duration: 5000,
|
||||
rtl: false
|
||||
},
|
||||
loadingIndicator: {},
|
||||
transition: {
|
||||
name: 'page',
|
||||
mode: 'out-in',
|
||||
appear: false,
|
||||
appearClass: 'appear',
|
||||
appearActiveClass: 'appear-active',
|
||||
appearToClass: 'appear-to'
|
||||
},
|
||||
layoutTransition: {
|
||||
name: 'layout',
|
||||
mode: 'out-in'
|
||||
},
|
||||
dir: {
|
||||
assets: 'assets',
|
||||
layouts: 'layouts',
|
||||
middleware: 'middleware',
|
||||
pages: 'pages',
|
||||
static: 'static',
|
||||
store: 'store'
|
||||
},
|
||||
router: {
|
||||
mode: 'history',
|
||||
base: '/',
|
||||
routes: [],
|
||||
middleware: [],
|
||||
linkActiveClass: 'nuxt-link-active',
|
||||
linkExactActiveClass: 'nuxt-link-exact-active',
|
||||
extendRoutes: null,
|
||||
scrollBehavior: null,
|
||||
parseQuery: false,
|
||||
stringifyQuery: false,
|
||||
fallback: false
|
||||
},
|
||||
render: {
|
||||
bundleRenderer: {},
|
||||
resourceHints: true,
|
||||
ssr: undefined,
|
||||
http2: {
|
||||
push: false,
|
||||
shouldPush: null
|
||||
},
|
||||
static: {
|
||||
prefix: true
|
||||
},
|
||||
gzip: {
|
||||
threshold: 0
|
||||
},
|
||||
etag: {
|
||||
weak: false
|
||||
},
|
||||
csp: {
|
||||
enabled: false,
|
||||
hashAlgorithm: 'sha256',
|
||||
allowedSources: undefined,
|
||||
policies: undefined
|
||||
}
|
||||
},
|
||||
watchers: {
|
||||
webpack: {},
|
||||
chokidar: {}
|
||||
},
|
||||
editor: undefined,
|
||||
hooks: null,
|
||||
messages: {
|
||||
error_404: 'This page could not be found',
|
||||
server_error: 'Server error',
|
||||
nuxtjs: 'Nuxt.js',
|
||||
back_to_home: 'Back to the home page',
|
||||
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.',
|
||||
client_error: 'Error',
|
||||
client_error_details:
|
||||
'An error occurred while rendering the page. Check developer tools console for details.'
|
||||
}
|
||||
}
|
@ -2,8 +2,12 @@ import _ from 'lodash'
|
||||
import Debug from 'debug'
|
||||
import { join, resolve } from 'path'
|
||||
import { existsSync, readdirSync } from 'fs'
|
||||
|
||||
import { isUrl, isPureObject } from '../common/utils'
|
||||
|
||||
import modes from './modes'
|
||||
import defaults from './nuxt.config'
|
||||
|
||||
const debug = Debug('nuxt:build')
|
||||
debug.color = 2 // Force green color
|
||||
|
||||
@ -44,14 +48,14 @@ Options.from = function (_options) {
|
||||
|
||||
// Apply defaults by ${buildDir}/dist/build.config.js
|
||||
// TODO: Unsafe operation.
|
||||
// const buildDir = options.buildDir || Options.defaults.buildDir
|
||||
// const buildDir = options.buildDir || defaults.buildDir
|
||||
// const buildConfig = resolve(options.rootDir, buildDir, 'build.config.js')
|
||||
// if (existsSync(buildConfig)) {
|
||||
// _.defaultsDeep(options, require(buildConfig))
|
||||
// }
|
||||
|
||||
// Apply defaults
|
||||
_.defaultsDeep(options, Options.defaults)
|
||||
_.defaultsDeep(options, defaults)
|
||||
|
||||
// Resolve dirs
|
||||
options.srcDir = hasValue(options.srcDir)
|
||||
@ -81,7 +85,7 @@ Options.from = function (_options) {
|
||||
// Ignore publicPath on dev
|
||||
/* istanbul ignore if */
|
||||
if (options.dev && isUrl(options.build.publicPath)) {
|
||||
options.build.publicPath = Options.defaults.build.publicPath
|
||||
options.build.publicPath = defaults.build.publicPath
|
||||
}
|
||||
|
||||
// If store defined, update store options to true unless explicitly disabled
|
||||
@ -138,8 +142,7 @@ Options.from = function (_options) {
|
||||
}
|
||||
|
||||
// Apply mode preset
|
||||
let modePreset =
|
||||
Options.modes[options.mode || 'universal'] || Options.modes['universal']
|
||||
const modePreset = modes[options.mode || 'universal'] || modes['universal']
|
||||
_.defaultsDeep(options, modePreset)
|
||||
|
||||
// If no server-side rendering, add appear true transition
|
||||
@ -155,203 +158,3 @@ Options.from = function (_options) {
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
Options.modes = {
|
||||
universal: {
|
||||
build: {
|
||||
ssr: true
|
||||
},
|
||||
render: {
|
||||
ssr: true
|
||||
}
|
||||
},
|
||||
spa: {
|
||||
build: {
|
||||
ssr: false
|
||||
},
|
||||
render: {
|
||||
ssr: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Options.unsafeKeys = [
|
||||
// 'rootDir', 'srcDir', 'buildDir', 'modulesDir', 'cacheDir', 'nuxtDir',
|
||||
// 'nuxtAppDir', 'build', 'generate', 'router.routes', 'appTemplatePath'
|
||||
// ]
|
||||
|
||||
Options.defaults = {
|
||||
mode: 'universal',
|
||||
dev: process.env.NODE_ENV !== 'production',
|
||||
debug: undefined, // Will be equal to dev if not provided
|
||||
buildDir: '.nuxt',
|
||||
cacheDir: '.cache',
|
||||
nuxtDir: resolve(__dirname, '../..'),
|
||||
nuxtAppDir: resolve(__dirname, '../app'),
|
||||
modulesDir: ['node_modules'], // ~> relative to options.rootDir
|
||||
ignorePrefix: '-',
|
||||
ignore: [
|
||||
'**/*.test.*'
|
||||
],
|
||||
extensions: [],
|
||||
build: {
|
||||
analyze: false,
|
||||
profile: process.argv.includes('--profile'),
|
||||
splitPages: true,
|
||||
maxChunkSize: false,
|
||||
extractCSS: false,
|
||||
cssSourceMap: undefined,
|
||||
ssr: undefined,
|
||||
publicPath: '/_nuxt/',
|
||||
filenames: {
|
||||
css: '[name].[contenthash].css',
|
||||
manifest: 'manifest.[hash].js',
|
||||
app: '[name].[chunkhash].js',
|
||||
chunk: '[name].[chunkhash].js'
|
||||
},
|
||||
styleResources: {},
|
||||
plugins: [],
|
||||
babel: {
|
||||
babelrc: false
|
||||
},
|
||||
postcss: {},
|
||||
templates: [],
|
||||
watch: [],
|
||||
devMiddleware: {},
|
||||
hotMiddleware: {},
|
||||
stats: {
|
||||
chunks: false,
|
||||
children: false,
|
||||
modules: false,
|
||||
colors: true,
|
||||
excludeAssets: [
|
||||
/.map$/,
|
||||
/index\..+\.html$/,
|
||||
/vue-ssr-client-manifest.json/
|
||||
]
|
||||
}
|
||||
},
|
||||
generate: {
|
||||
dir: 'dist',
|
||||
routes: [],
|
||||
concurrency: 500,
|
||||
interval: 0,
|
||||
subFolders: true,
|
||||
fallback: '200.html',
|
||||
minify: {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseWhitespace: false,
|
||||
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,
|
||||
sortClassName: false,
|
||||
trimCustomFragments: true,
|
||||
useShortDoctype: true
|
||||
}
|
||||
},
|
||||
env: {},
|
||||
head: {
|
||||
meta: [],
|
||||
link: [],
|
||||
style: [],
|
||||
script: []
|
||||
},
|
||||
plugins: [],
|
||||
css: [],
|
||||
modules: [],
|
||||
layouts: {},
|
||||
serverMiddleware: [],
|
||||
ErrorPage: null,
|
||||
loading: {
|
||||
color: 'black',
|
||||
failedColor: 'red',
|
||||
height: '2px',
|
||||
duration: 5000,
|
||||
rtl: false
|
||||
},
|
||||
loadingIndicator: {},
|
||||
transition: {
|
||||
name: 'page',
|
||||
mode: 'out-in',
|
||||
appear: false,
|
||||
appearClass: 'appear',
|
||||
appearActiveClass: 'appear-active',
|
||||
appearToClass: 'appear-to'
|
||||
},
|
||||
layoutTransition: {
|
||||
name: 'layout',
|
||||
mode: 'out-in'
|
||||
},
|
||||
dir: {
|
||||
assets: 'assets',
|
||||
layouts: 'layouts',
|
||||
middleware: 'middleware',
|
||||
pages: 'pages',
|
||||
static: 'static',
|
||||
store: 'store'
|
||||
},
|
||||
router: {
|
||||
mode: 'history',
|
||||
base: '/',
|
||||
routes: [],
|
||||
middleware: [],
|
||||
linkActiveClass: 'nuxt-link-active',
|
||||
linkExactActiveClass: 'nuxt-link-exact-active',
|
||||
extendRoutes: null,
|
||||
scrollBehavior: null,
|
||||
parseQuery: false,
|
||||
stringifyQuery: false,
|
||||
fallback: false
|
||||
},
|
||||
render: {
|
||||
bundleRenderer: {},
|
||||
resourceHints: true,
|
||||
ssr: undefined,
|
||||
http2: {
|
||||
push: false,
|
||||
shouldPush: null
|
||||
},
|
||||
static: {
|
||||
prefix: true
|
||||
},
|
||||
gzip: {
|
||||
threshold: 0
|
||||
},
|
||||
etag: {
|
||||
weak: false
|
||||
},
|
||||
csp: {
|
||||
enabled: false,
|
||||
hashAlgorithm: 'sha256',
|
||||
allowedSources: undefined,
|
||||
policies: undefined
|
||||
}
|
||||
},
|
||||
watchers: {
|
||||
webpack: {},
|
||||
chokidar: {}
|
||||
},
|
||||
editor: undefined,
|
||||
hooks: null,
|
||||
messages: {
|
||||
error_404: 'This page could not be found',
|
||||
server_error: 'Server error',
|
||||
nuxtjs: 'Nuxt.js',
|
||||
back_to_home: 'Back to the home page',
|
||||
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.',
|
||||
client_error: 'Error',
|
||||
client_error_details:
|
||||
'An error occurred while rendering the page. Check developer tools console for details.'
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import launchMiddleware from 'launch-editor-middleware'
|
||||
import crypto from 'crypto'
|
||||
|
||||
import { setAnsiColors, isUrl, waitFor, timeout } from '../common/utils'
|
||||
import Options from '../common/options'
|
||||
import defaults from '../common/nuxt.config'
|
||||
|
||||
import MetaRenderer from './meta'
|
||||
import errorMiddleware from './middleware/error'
|
||||
@ -202,7 +202,7 @@ export default class Renderer {
|
||||
|
||||
get publicPath() {
|
||||
return isUrl(this.options.build.publicPath)
|
||||
? Options.defaults.build.publicPath
|
||||
? defaults.build.publicPath
|
||||
: this.options.build.publicPath
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user