2016-11-10 02:38:11 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-01-11 19:14:59 +00:00
|
|
|
import webpack from 'webpack'
|
2017-03-22 14:47:34 +00:00
|
|
|
import VueSSRPlugin from 'vue-ssr-webpack-plugin'
|
2017-01-11 19:14:59 +00:00
|
|
|
import base from './base.config.js'
|
|
|
|
import { each, uniq } from 'lodash'
|
|
|
|
import { existsSync, readFileSync } from 'fs'
|
|
|
|
import { resolve } from 'path'
|
2016-11-07 01:34:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Webpack Server Config
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
2017-01-11 19:14:59 +00:00
|
|
|
export default function () {
|
2017-01-09 14:10:22 +00:00
|
|
|
let config = base.call(this, { isServer: true })
|
2016-11-09 22:59:41 +00:00
|
|
|
|
2016-11-25 14:37:06 +00:00
|
|
|
// env object defined in nuxt.config.js
|
|
|
|
let env = {}
|
2017-01-11 19:14:59 +00:00
|
|
|
each(this.options.env, (value, key) => {
|
2016-11-25 14:37:06 +00:00
|
|
|
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',
|
2017-03-25 02:17:15 +00:00
|
|
|
devtool: (this.dev ? 'source-map' : false),
|
2016-11-09 22:59:41 +00:00
|
|
|
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'
|
|
|
|
}),
|
2017-03-27 16:06:57 +00:00
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
2016-11-17 21:12:21 +00:00
|
|
|
plugins: (config.plugins || []).concat([
|
2017-03-22 14:47:34 +00:00
|
|
|
new VueSSRPlugin({
|
|
|
|
filename: 'server-bundle.json'
|
|
|
|
}),
|
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'),
|
2017-02-28 12:10:58 +00:00
|
|
|
'process.BROWSER_BUILD': false, // deprecated
|
|
|
|
'process.SERVER_BUILD': true, // deprecated
|
|
|
|
'process.browser': false,
|
|
|
|
'process.server': 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
|
|
|
})
|
2017-03-24 00:28:04 +00:00
|
|
|
// This is needed in webpack 2 for minifying CSS
|
|
|
|
if (!this.dev) {
|
|
|
|
config.plugins.push(
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2016-11-09 22:59:41 +00:00
|
|
|
// Externals
|
2017-01-19 15:25:32 +00:00
|
|
|
const nuxtPackageJson = require('../../package.json')
|
2016-12-09 17:54:17 +00:00
|
|
|
const projectPackageJsonPath = resolve(this.dir, 'package.json')
|
2016-11-09 22:59:41 +00:00
|
|
|
config.externals = Object.keys(nuxtPackageJson.dependencies || {})
|
2016-12-09 17:54:17 +00:00
|
|
|
if (existsSync(projectPackageJsonPath)) {
|
|
|
|
try {
|
|
|
|
const projectPackageJson = JSON.parse(readFileSync(projectPackageJsonPath))
|
|
|
|
config.externals = config.externals.concat(Object.keys(projectPackageJson.dependencies || {}))
|
|
|
|
} catch (e) {}
|
2016-11-09 22:59:41 +00:00
|
|
|
}
|
2017-03-24 02:57:07 +00:00
|
|
|
config.externals = config.externals.concat(this.options.build.vendor)
|
2016-11-09 22:59:41 +00:00
|
|
|
config.externals = uniq(config.externals)
|
|
|
|
|
2016-12-27 13:54:10 +00:00
|
|
|
// Extend config
|
|
|
|
if (typeof this.options.build.extend === 'function') {
|
|
|
|
this.options.build.extend(config, {
|
|
|
|
dev: this.dev,
|
|
|
|
isServer: true
|
|
|
|
})
|
|
|
|
}
|
2016-11-09 22:59:41 +00:00
|
|
|
return config
|
|
|
|
}
|