1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-25 13:51:45 +03:00
guide/front/build/webpack.server.conf.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

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')
const axios = require('axios')
const { distPath, env, ssrPort } = require('./build-config')
const baseConfig = require('./webpack.base.conf')
axios.defaults.baseURL = `http://localhost:${ssrPort}`
const webpackConfig = merge(baseConfig, {
mode: process.env.NODE_ENV,
target: 'node',
entry: rootResolve('./client/entry.server.ts'),
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)
}