Nuxt/lib/webpack/server.config.js

73 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict'
2017-01-11 19:14:59 +00:00
import webpack from 'webpack'
import VueSSRServerPlugin from 'vue-server-renderer/server-plugin'
2017-05-24 13:04:17 +00:00
import nodeExternals from 'webpack-node-externals'
2017-01-11 19:14:59 +00:00
import base from './base.config.js'
2017-05-24 13:04:17 +00:00
import { each } from 'lodash'
2017-01-11 19:14:59 +00:00
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-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)
})
config = Object.assign(config, {
target: 'node',
2017-03-25 02:17:15 +00:00
devtool: (this.dev ? 'source-map' : false),
2017-05-23 23:52:48 +00:00
entry: resolve(this.buildDir, 'server.js'),
2016-11-10 18:34:59 +00:00
output: Object.assign({}, config.output, {
2017-05-23 23:52:48 +00:00
path: resolve(this.buildDir, 'dist'),
filename: 'server-bundle.js',
libraryTarget: 'commonjs2'
}),
2017-03-27 16:06:57 +00:00
performance: {
hints: false
},
2017-05-24 13:04:17 +00:00
externals: [
nodeExternals({
// load non-javascript files with extensions, presumably via loaders
whitelist: [/\.(?!(?:js|json)$).{1,5}$/i]
})
],
plugins: (config.plugins || []).concat([
new VueSSRServerPlugin({
2017-03-22 14:47:34 +00:00
filename: 'server-bundle.json'
}),
2016-11-25 14:37:06 +00:00
new webpack.DefinePlugin(Object.assign(env, {
'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
}))
])
})
// This is needed in webpack 2 for minifying CSS
if (!this.dev) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
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
})
}
return config
}