forked from vuejs/vuepress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateServerConfig.js
58 lines (48 loc) · 1.41 KB
/
createServerConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module.exports = function createServerConfig (options, cliOptions) {
const fs = require('fs')
const path = require('path')
const WebpackBar = require('webpackbar')
const createBaseConfig = require('./createBaseConfig')
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const config = createBaseConfig(options, cliOptions, true /* isServer */)
const { sourceDir, outDir } = options
config
.target('node')
.externals([/^(vue|vue-router)$/])
.devtool('source-map')
// no need to minimize server build
config.optimization.minimize(false)
config
.entry('app')
.add(path.resolve(__dirname, '../app/serverEntry.js'))
config.output
.filename('server-bundle.js')
.libraryTarget('commonjs2')
config
.plugin('ssr-server')
.use(VueSSRServerPlugin, [{
filename: 'manifest/server.json'
}])
const publicDir = path.resolve(sourceDir, '.vuepress/public')
if (fs.existsSync(publicDir)) {
config
.plugin('copy')
.use(CopyPlugin, [[
{ from: publicDir, to: outDir }
]])
}
if (!cliOptions.debug) {
config
.plugin('bar')
.use(WebpackBar, [{
name: 'Server',
color: 'blue',
compiledIn: false
}])
}
if (options.siteConfig.chainWebpack) {
options.siteConfig.chainWebpack(config, true /* isServer */)
}
return config
}