2018-09-02 23:26:15 +03:00
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
const webpack = require('webpack')
|
|
|
|
const merge = require('webpack-merge')
|
|
|
|
const nodeExternals = require('webpack-node-externals')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
|
|
const VueServerPlugin = require('vue-server-renderer/server-plugin')
|
2018-10-03 00:07:01 +03:00
|
|
|
const axios = require('axios')
|
|
|
|
const { distPath, env, ssrPort } = require('./build-config')
|
2018-09-02 23:26:15 +03:00
|
|
|
const baseConfig = require('./webpack.base.conf')
|
|
|
|
|
2018-10-03 00:07:01 +03:00
|
|
|
axios.defaults.baseURL = `http://localhost:${ssrPort}`
|
|
|
|
|
2018-09-02 23:26:15 +03:00
|
|
|
const webpackConfig = merge(baseConfig, {
|
|
|
|
mode: process.env.NODE_ENV,
|
|
|
|
|
|
|
|
target: 'node',
|
|
|
|
|
|
|
|
entry: rootResolve('./client/entry.server.ts'),
|
2018-10-03 00:07:01 +03:00
|
|
|
|
2018-09-02 23:26:15 +03:00
|
|
|
output: {
|
|
|
|
path: distPath,
|
|
|
|
filename: 'server-build.js',
|
|
|
|
libraryTarget: 'commonjs2'
|
|
|
|
},
|
|
|
|
|
|
|
|
externals: nodeExternals({
|
|
|
|
whitelist: [
|
|
|
|
/\.css$/,
|
|
|
|
/\.vue$/,
|
|
|
|
/babel-polyfill/
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new VueServerPlugin(),
|
|
|
|
|
|
|
|
new webpack.DefinePlugin(Object.assign({}, env, {
|
|
|
|
'process.env.VUE_ENV': JSON.stringify('server')
|
|
|
|
}))
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
switch (process.env.NODE_ENV) {
|
|
|
|
case 'production':
|
|
|
|
webpackConfig.plugins.push(
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'static/css/[name].[contenthash].css',
|
|
|
|
chunkFilename: 'static/css/[id].[contenthash].css'
|
|
|
|
})
|
|
|
|
)
|
|
|
|
webpackConfig.optimization.splitChunks = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = webpackConfig
|
|
|
|
|
|
|
|
function rootResolve (filePath) {
|
|
|
|
return path.resolve(__dirname, '../', filePath)
|
|
|
|
}
|