webpack.client.conf.js 1.53 KB
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const shelljs = require('shelljs');

let baseConfig = require('./webpack.base.conf');

shelljs.exec(`cp -R ${path.join(__dirname, '../public/font/')} ${path.join(__dirname, '../src/statics')}`, {async: true});
shelljs.exec(`cp -R ${path.join(__dirname, '../public/img/')} ${path.join(__dirname, '../src/statics')}`, {async: true});

const webpackConfig = merge(baseConfig, {
    entry: {
        app: './src/entry-client.js'
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
            'process.env.VUE_ENV': '"client"'
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            minChunks: function(module) {
                return (
                    /node_modules/.test(module.context) &&
                    !/\.css$/.test(module.request)
                );
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'manifest',
        }),
        new VueSSRClientPlugin()
    ]
});

if (process.env.NODE_ENV === 'production') {
    webpackConfig.plugins.push(new UglifyJSPlugin({
        parallel: true,
        sourceMap: true
    }));
    webpackConfig.output.publicPath = '//cdn.yoho.cn/yohoblk-wap/';

}

module.exports = webpackConfig;