如何使用webpack为多个目标构建?

时间:2019-04-24 09:33:07

标签: node.js webpack webpack-4

我遵循docs并实现了如下所示的内容:

function validation_altered_data()
{   
    var a = $('select[name=table_time_records_length]').val();
    $('select[name=table_time_records_length]').append("<option id='optioncount' value='365'></option>");
    $('select[name=table_time_records_length]').val(365).trigger('change');


    counter_alter_validation = 0;
    for(i = 1; i <=100; i++)
    {
        var sam = $('#timein' + i).val();
        var date = new Date(sam);
        month = date.getMonth()+1;

        if(month < 10)
        {
            var month_format = "0" + (date.getMonth()+1);
        }
        else
        {
            var month_format = (date.getMonth()+1);
        }

        var this_date = date.getDate();
        if(this_date >= 10)
        {
            var day_format = date.getDate();
        }
        else
        {
            var day_format = "0"+ date.getDate();
        }

        var res = date.getFullYear() + "-" + month_format + "-" + day_format;

        if($('#checkalt' + i))
        {
            if($('#checkalt' + i).prop("checked") == true)
            {
                var date_to_alter = $('#infos' + i).val().split("]]");

                counter_alter_validation++;
                if($('#txtReason_apply').val() == ""){
                    az = "1";
                    checker_validation = "false";
                    error="Reason for Alteration is Required!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                //If time in or time out IS EMPTY
                else if($('#timeout' + i).val() == "" || $('#timein' + i).val() == "")
                {
                    az = "2";
                    checker_validation = "false";
                    error="Time In field and Time Out field is required!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                else if($('#timeout' + i).val() <= $('#timein' + i).val())
                {
                    az = "3";
                    checker_validation = "false";
                    error="Time Out field must be greater than Time In field!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                else if(res != date_to_alter[0])
                {
                    az = "4";
                    checker_validation = "false";
                    error="Invalid Details, Check Time in and Time out!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                //Avoid saving the current date, If the user removes disabled attribute in the inspect elements
                else if(date_to_alter[0] == curDate)
                {
                    az = "5";
                    checker_validation = "false";
                    error="You can't alter the current date!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                else if($('#validateStatus' + i).val() == "Punch Altered")
                {
                    az = "6";
                    checker_validation = "false";
                    error = "You can't edit altered rows!";
                    $("select[name=table_time_records_length] option[value='365']").remove(); 
                    $('select[name=table_time_records_length]').val(a).trigger('change');
                    break;
                }
                else
                {
                    checker_validation = "true";
                }
            }
        }
    }
}

但是,只有一个目标通过,我认为没有确定性的过程来确定哪个目标被构建(也就是说,有时是Web目标被构建,而其他时候是节点目标)。

我不确定在上面的配置中我做错了什么,但是我觉得在某些竞速条件下,一个目标要先于另一个而先建立,因此节点进程在建立两个目标之前就退出了。是这样吗这是我的common config

我使用的webpack版本是... const config = { mode: 'development', devtool: 'inline-source-map', }; const nodeConfig = merge(common, { ...config, output: { filename: 'bundle.node.js', }, target: 'node', }); const webConfig = merge(common, { ...config, node: { crypto: true, }, output: { filename: 'bundle.web.js', }, target: 'web', }); module.exports = [nodeConfig, webConfig];

1 个答案:

答案 0 :(得分:0)

我整理了一下。在我的常用配置中,我使用的是clean-webpack-plugin

plugins: [
    new CleanWebpackPlugin(),
    ...
]

很明显,在构建第二个目标时,干净的插件正在擦除第一个目标。

特别是如果您是从CI部署的,则实际上并不需要此插件。