Webpack-如何设置简单的多应用程序构建

时间:2018-11-24 12:27:28

标签: webpack

用例

我已经设置了一个节点服务器,以便每当有人导航到app1.domain.com时,它将加载静态站点app1。

我有多个应用。 app1,app2和app3。每个应用程序文件夹都有其自己的index.html,index.js和index.scss。它们都是简单的React应用。他们的目录结构是这样的。

源目录

enter image description here


我已经构建了以下webpack配置,该配置将我的react应用程序与我的scss一起编译/构建到一个名为bundle.js的文件中。另外,我正在复制html文件。它输出到dist / public /

webpack.config.js

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private Context context;
    private Img[] data;

    public MyAdapter(Context context, Img[] data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.image_row, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        final Img user = data[position];

        final String imageStr = user.getImgurl();
        String taKey = loadTaluka();
        final String id = user.getImgId().toString();

        if (user.getTaluka().equals(taKey)) {
            float date = Float.parseFloat(user.getDateTime());
            float lastDayDate = Float.parseFloat(dispDate()) - 1;
            if (date >= lastDayDate) {
                Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).networkPolicy(NetworkPolicy.OFFLINE).into(holder.myImg, new Callback() {
                    @Override
                    public void onSuccess() {
                    }

                    @Override
                    public void onError() {
                        Picasso.with(holder.myImg.getContext()).load(imageStr).placeholder(R.drawable.loading_1).into(holder.myImg);
                    }
                });



            }
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LoadImg.class);
                    intent.putExtra("url", imageStr);
                    intent.putExtra("id", id);
                    context.startActivity(intent);
                }
            });

        }

    }

    @Override
    public int getItemCount() {
        return data.length;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


/*
    @Override
    public int getItemViewType(int position) {
        return position;
    }*/
    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView userTitle;
        TextView age;
        TextView country;
        TextView url;
        public ImageView myImg;

        public MyViewHolder(View itemView) {
            super(itemView);
            myImg = (ImageView) itemView.findViewById(R.id.postImg);
        }
    }


    //Extras


    private String loadTaluka() {
        SharedPreferences sf = context.getSharedPreferences("Taluka", MODE_PRIVATE);
        return sf.getString("taluka", "a");
    }

    //Image Viewholder Adapter End
    private String dispDate() {
        Date c = Calendar.getInstance().getTime();

        @SuppressLint("SimpleDateFormat") SimpleDateFormat day = new SimpleDateFormat("dd");
        String dayFinal = day.format(c);

        @SuppressLint("SimpleDateFormat") SimpleDateFormat month = new SimpleDateFormat("MM");
        String monthFinal = month.format(c);

        @SuppressLint("SimpleDateFormat") SimpleDateFormat year = new SimpleDateFormat("yyyy");
        String yearFinal = year.format(c);

        @SuppressLint("SimpleDateFormat") SimpleDateFormat hour = new SimpleDateFormat("HH");
        String hourFinal = hour.format(c);

        String finalDate = Integer.toString(Integer.parseInt(dayFinal) + Integer.parseInt(monthFinal) + Integer.parseInt(yearFinal)) + "." + hourFinal;

        return finalDate;
    }


}

  -Thankyou.

我如何扩展此配置,以便它可以自动对其他文件夹(如app2和app3)执行此操作。 (现在我只为app1做)。

这是当前输出的示例,我希望app2和app3会看到相同的结果。

输出

enter image description here

0 个答案:

没有答案