2018-03-16 19:52:17 +00:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
|
|
|
|
2018-03-16 16:12:06 +00:00
|
|
|
import webpack from 'webpack'
|
|
|
|
import nodeExternals from 'webpack-node-externals'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2018-03-22 16:22:41 +00:00
|
|
|
import BaseConfig from './base'
|
2018-03-16 19:52:17 +00:00
|
|
|
import VueSSRServerPlugin from './plugins/vue/server'
|
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
export default class WebpackServerConfig extends BaseConfig {
|
|
|
|
constructor(builder) {
|
|
|
|
super(builder, { name: 'server', isServer: true })
|
|
|
|
}
|
2016-11-25 14:37:06 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
env() {
|
|
|
|
return Object.assign(super.env(), {
|
|
|
|
'process.env.VUE_ENV': JSON.stringify('server'),
|
|
|
|
'process.browser': false,
|
|
|
|
'process.client': false,
|
|
|
|
'process.server': true
|
|
|
|
})
|
|
|
|
}
|
2018-01-04 23:34:20 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
plugins() {
|
|
|
|
const plugins = super.plugins()
|
|
|
|
plugins.push(
|
2017-04-27 08:54:18 +00:00
|
|
|
new VueSSRServerPlugin({
|
2017-03-22 14:47:34 +00:00
|
|
|
filename: 'server-bundle.json'
|
|
|
|
}),
|
2018-03-22 14:06:54 +00:00
|
|
|
new webpack.DefinePlugin(this.env())
|
|
|
|
)
|
|
|
|
return plugins
|
|
|
|
}
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
config() {
|
|
|
|
let config = super.config()
|
|
|
|
|
|
|
|
// Config devtool
|
2018-03-23 18:30:47 +00:00
|
|
|
config.devtool = 'cheap-source-map'
|
2017-07-31 23:28:53 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
Object.assign(config, {
|
|
|
|
target: 'node',
|
|
|
|
node: false,
|
|
|
|
entry: path.resolve(this.options.buildDir, 'server.js'),
|
|
|
|
output: Object.assign({}, config.output, {
|
|
|
|
filename: 'server-bundle.js',
|
|
|
|
libraryTarget: 'commonjs2'
|
|
|
|
}),
|
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
maxAssetSize: Infinity
|
|
|
|
},
|
2018-03-23 18:30:47 +00:00
|
|
|
externals: [],
|
|
|
|
optimization: {
|
|
|
|
splitChunks: false,
|
|
|
|
minimizer: []
|
|
|
|
}
|
2018-03-22 14:06:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// https://webpack.js.org/configuration/externals/#externals
|
|
|
|
// https://github.com/liady/webpack-node-externals
|
2018-05-02 08:27:26 +00:00
|
|
|
// https://vue-loader.vuejs.org/migrating.html#ssr-externals
|
2018-08-06 00:12:44 +00:00
|
|
|
this.options.modulesDir.forEach((dir) => {
|
2018-03-22 14:06:54 +00:00
|
|
|
if (fs.existsSync(dir)) {
|
|
|
|
config.externals.push(
|
|
|
|
nodeExternals({
|
2018-05-02 08:27:26 +00:00
|
|
|
whitelist: [
|
|
|
|
/es6-promise|\.(?!(?:js|json)$).{1,5}$/i,
|
|
|
|
/\.css$/,
|
2018-07-31 13:10:24 +00:00
|
|
|
/\?vue&type=style/,
|
|
|
|
...this.options.build.transpile
|
2018-05-02 08:27:26 +00:00
|
|
|
],
|
2018-03-22 14:06:54 +00:00
|
|
|
modulesDir: dir
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2016-12-27 13:54:10 +00:00
|
|
|
})
|
2018-03-22 14:06:54 +00:00
|
|
|
|
|
|
|
// Extend config
|
|
|
|
if (typeof this.options.build.extend === 'function') {
|
|
|
|
const isDev = this.options.dev
|
|
|
|
const extendedConfig = this.options.build.extend.call(this.builder, config, {
|
|
|
|
isDev,
|
|
|
|
isServer: true
|
|
|
|
})
|
|
|
|
// Only overwrite config when something is returned for backwards compatibility
|
|
|
|
if (extendedConfig !== undefined) {
|
|
|
|
config = extendedConfig
|
|
|
|
}
|
2017-08-21 20:21:16 +00:00
|
|
|
}
|
2017-06-15 22:19:53 +00:00
|
|
|
|
2018-03-22 14:06:54 +00:00
|
|
|
return config
|
|
|
|
}
|
2016-11-09 22:59:41 +00:00
|
|
|
}
|