2016-11-10 02:38:11 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-11-25 14:37:06 +00:00
|
|
|
const _ = require('lodash')
|
2016-11-07 01:34:58 +00:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const base = require('./base.config')
|
2016-11-09 22:59:41 +00:00
|
|
|
const { uniq } = require('lodash')
|
|
|
|
const { existsSync } = require('fs')
|
|
|
|
const { resolve } = require('path')
|
2016-11-07 01:34:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Webpack Server Config
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
2016-11-09 22:59:41 +00:00
|
|
|
module.exports = function () {
|
|
|
|
let config = base.call(this)
|
|
|
|
|
2016-11-25 14:37:06 +00:00
|
|
|
// env object defined in nuxt.config.js
|
|
|
|
let env = {}
|
|
|
|
_.each(this.options.env, (value, key) => {
|
|
|
|
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
|
|
|
|
})
|
|
|
|
|
2016-11-09 22:59:41 +00:00
|
|
|
config = Object.assign(config, {
|
|
|
|
target: 'node',
|
|
|
|
devtool: false,
|
|
|
|
entry: resolve(this.dir, '.nuxt', 'server.js'),
|
2016-11-10 18:34:59 +00:00
|
|
|
output: Object.assign({}, config.output, {
|
2016-11-09 22:59:41 +00:00
|
|
|
path: resolve(this.dir, '.nuxt', 'dist'),
|
|
|
|
filename: 'server-bundle.js',
|
|
|
|
libraryTarget: 'commonjs2'
|
|
|
|
}),
|
2016-11-17 21:12:21 +00:00
|
|
|
plugins: (config.plugins || []).concat([
|
2016-11-25 14:37:06 +00:00
|
|
|
new webpack.DefinePlugin(Object.assign(env, {
|
2016-11-09 22:59:41 +00:00
|
|
|
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
2016-11-24 00:46:20 +00:00
|
|
|
'process.BROWSER_BUILD': false,
|
|
|
|
'process.SERVER_BUILD': true
|
2016-11-25 14:37:06 +00:00
|
|
|
}))
|
2016-11-17 21:12:21 +00:00
|
|
|
])
|
2016-11-09 22:59:41 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Externals
|
|
|
|
const nuxtPackageJson = require(resolve(__dirname, '..', '..', '..', 'package.json'))
|
|
|
|
const projectPackageJson = resolve(this.dir, 'package.json')
|
|
|
|
config.externals = Object.keys(nuxtPackageJson.dependencies || {})
|
|
|
|
if (existsSync(projectPackageJson)) {
|
|
|
|
config.externals = config.externals.concat(Object.keys(require(projectPackageJson).dependencies || {}))
|
|
|
|
}
|
|
|
|
config.externals = uniq(config.externals)
|
|
|
|
|
|
|
|
// Return config
|
|
|
|
return config
|
|
|
|
}
|