webpack.server.conf.js
1.45 KB
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
const webpack = require('webpack');
const merge = require('webpack-merge');
const nodeExternals = require('webpack-node-externals');
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin');
let baseConfig = require('./webpack.base.conf');
const pkg = require('../package.json');
const postcssConfig = require('./postcss.config.js');
const isProd = process.env.NODE_ENV === 'production';
let webpackConfig = merge(baseConfig, {
entry: './src/entry-server.js',
target: 'node',
output: {
libraryTarget: 'commonjs2',
},
resolve: {
alias: {
hammerjs$: 'vue-touch/dist/hammer-ssr.js',
'create-api': 'common/create-api-server.js'
}
},
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: isProd,
postcss: {
plugins: postcssConfig.plugins,
options: postcssConfig
}
}
}]
},
externals: nodeExternals({
whitelist: [/\.css$/, /vue-touch/, /hammerjs/]
}),
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.VUE_ENV': '"server"'
}),
new VueSSRServerPlugin({
filename: `yoho-ssr-server-${pkg.version}.json`
}),
]
});
module.exports = webpackConfig;