mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-11 14:57:15 +00:00
feat(build): add build.includeConfig to embed nuxt.config in dist after building (#2313)
* feat(build): add build.includeConfig to embed nuxt.config in dist after building * refactor: remove build.includeConfig and Options.safeKeys
This commit is contained in:
parent
aeb13eb8a0
commit
99d7177d90
@ -17,6 +17,7 @@ import serverWebpackConfig from './webpack/server.config.js'
|
||||
import dllWebpackConfig from './webpack/dll.config.js'
|
||||
import vueLoaderConfig from './webpack/vue-loader.config'
|
||||
import styleLoader from './webpack/style-loader'
|
||||
import { Options } from 'common'
|
||||
|
||||
const debug = Debug('nuxt:build')
|
||||
debug.color = 2 // Force green color
|
||||
@ -62,6 +63,8 @@ export default class Builder {
|
||||
// Stop watching on nuxt.close()
|
||||
if (this.options.dev) {
|
||||
this.nuxt.hook('close', () => this.unwatch())
|
||||
} else {
|
||||
this.nuxt.hook('build:done', () => this.generateConfig())
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,6 +562,12 @@ export default class Builder {
|
||||
// Stop webpack middleware
|
||||
await this.webpackDevMiddleware.close()
|
||||
}
|
||||
|
||||
async generateConfig() {
|
||||
const config = resolve(this.options.buildDir, 'build.config.js')
|
||||
const options = _.omit(this.options, Options.unsafeKeys)
|
||||
await writeFile(config, `module.exports = ${JSON.stringify(options, null, ' ')}`, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
const STATUS = {
|
||||
|
@ -32,12 +32,19 @@ Options.from = function (_options) {
|
||||
options.layoutTransition = { name: options.layoutTransition }
|
||||
}
|
||||
|
||||
const hasValue = v => typeof v === 'string' && v
|
||||
options.rootDir = hasValue(options.rootDir) ? options.rootDir : process.cwd()
|
||||
|
||||
// Apply defaults by ${buildDir}/dist/build.config.js
|
||||
const buildDir = options.buildDir || Options.defaults.buildDir
|
||||
const buildConfig = resolve(options.rootDir, buildDir, 'build.config.js')
|
||||
if (existsSync(buildConfig)) {
|
||||
_.defaultsDeep(options, require(buildConfig))
|
||||
}
|
||||
// Apply defaults
|
||||
_.defaultsDeep(options, Options.defaults)
|
||||
|
||||
// Resolve dirs
|
||||
const hasValue = v => typeof v === 'string' && v
|
||||
options.rootDir = hasValue(options.rootDir) ? options.rootDir : process.cwd()
|
||||
options.srcDir = hasValue(options.srcDir) ? resolve(options.rootDir, options.srcDir) : options.rootDir
|
||||
options.buildDir = resolve(options.rootDir, options.buildDir)
|
||||
options.cacheDir = resolve(options.rootDir, options.cacheDir)
|
||||
@ -185,6 +192,11 @@ Options.modes = {
|
||||
}
|
||||
}
|
||||
|
||||
Options.unsafeKeys = [
|
||||
'rootDir', 'srcDir', 'buildDir', 'modulesDir', 'cacheDir', 'nuxtDir',
|
||||
'nuxtAppDir', 'build', 'generate', 'router.routes', 'appTemplatePath'
|
||||
]
|
||||
|
||||
Options.defaults = {
|
||||
mode: 'universal',
|
||||
dev: process.env.NODE_ENV !== 'production',
|
||||
|
Loading…
Reference in New Issue
Block a user