webpack.client.conf.js 2.38 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 pkg = require('../package.json');
const shelljs = require('shelljs');

let baseConfig = require('./webpack.base.conf');
const postcssConfig = require('./postcss.config.js');

const isProd = process.env.NODE_ENV === 'production';

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

const webpackConfig = merge(baseConfig, {
    entry: {
        app: './src/entry-client.js'
    },
    devtool: isProd ? '#source-map' : '#cheap-module-source-map',
    module: {
        rules: [{
            test: /\.vue$/,
            loader: 'vue-loader',
            options: {
                extractCSS: isProd,
                postcss: {
                    plugins: postcssConfig.plugins,
                    options: postcssConfig
                },
                loaders: {
                    client: 'babel-loader'
                }
            }
        }]
    },
    resolve: {
        alias: {
            'create-api': 'common/create-api-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({
            filename: `yoho-ssr-client-${pkg.version}.json`
        })
    ]
});

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

}
module.exports = webpackConfig;