Skip to content
Snippets Groups Projects
webpack.config.js 1.35 KiB
Newer Older
const webpackMerge = require('webpack-merge');
Art Lowel's avatar
Art Lowel committed

lotte's avatar
lotte committed
const prodPartial = require('./webpack/webpack.prod');
Art Lowel's avatar
Art Lowel committed

lotte's avatar
lotte committed
module.exports = function (env, options) {
    env = env || {};
lotte's avatar
lotte committed
    const commonPartial = require('./webpack/webpack.common')(env);
    const clientPartial = require('./webpack/webpack.client')(env);
    const {getAotPlugin} = require('./webpack/webpack.aot')(env);
    const {getServerWebpackPartial} = require('./webpack/webpack.server')(env);

    if (env.aot) {
        console.log(`Running build for ${env.client ? 'client' : 'server'} with AoT Compilation`)
    }

    let serverPartial = getServerWebpackPartial(env.aot);

    let serverConfig = webpackMerge({}, commonPartial, serverPartial, {
        plugins: [
            getAotPlugin('server', !!env.aot)
        ]
    });

    let clientConfig = webpackMerge({}, commonPartial, clientPartial, {
        plugins: [
            getAotPlugin('client', !!env.aot)
        ]
    });
    if (options.mode === 'production') {
        serverConfig = webpackMerge({}, serverConfig, prodPartial);
        clientConfig = webpackMerge({}, clientConfig, prodPartial);
    }

    const configs = [];

    if (!env.aot) {
        configs.push(clientConfig, serverConfig);
    } else if (env.client) {
        configs.push(clientConfig);
    } else if (env.server) {
        configs.push(serverConfig);
    }

    return configs;