webpack.server.conf.js 1.45 KB
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;