Takeshi Tokugawa YD
Takeshi Tokugawa YD

Reputation: 915

How to copy "node_modules" using by "webpack-node-externals" to directory with production building?

Consider the full-stack application project with NodeJS back-end.

enter image description here

Now: how to copy to 02-ProductionBuild only those dependencies, which using EntryPoint-BackEnd.js via webpack-node-externals?

enter image description here

I glad if can reach it by webpack-node-externals, but if impossible, other tools are welcome.

The basic practice is deploying the full project to host and installing dependencies by npm install. However all that we need for working application in server is 02-ProductionBuild folder including dependencies for EntryPoint-BackEnd.js.

Upvotes: 3

Views: 713

Answers (1)

JRichardsz
JRichardsz

Reputation: 16505

Root of problems

  • You have one repository to several applications
  • You have centralized frontend and backend dependecies in one file: package.json

Workaround

  • Create a npm module capable of create a package.json for each application in your repository. Fictional name: packagify
  • Add scripts in your package.json to perform separate builds
    {
      "build:frontend" : "packagify ....",
      "build:backend" : "packagify ...."
    }
  • If you don't want the elegant way of create a new npm library, you can create a simple packagify.js file and invoke it from your scripts:
    {
      "build:frontend" : "packagify.js ....",
      "build:backend" : "packagify.js ...."
    }

Some Advices

  • Don't merge several apps in one source code repository. Each app must have its own source code repository
  • Split your current repository in two repositories: One for your frontend and one for your backend
  • If each app has its source code repository, you will not have problems to build or deploy them. This is called: Independent deployment
  • If your organization will grow, you could avoid a new monolithic using microfrontends

Monolothic Frontend

Since you are using vue, it is sure that your backend is a rest api. So you are close to the classic approach which is opposite to a monolithic application.

One monolithic characteristic:

  • frontend and backend source code are in the same repository

web-and-microservice

But what happen if you put dozens of web features in the same web application? A new monster is born:

monolithic-web

Microfrontend & Microservices

As a extremely summary, microfronted is the same as microservice but for frontends

microfrontend-miroservice

As you should already know, microservices has a lot of advantages. These advantages also applies to microfrontends. One of most important is: Independent deployment

Independent deployment

Independent deployment

Just as with microservices, independent deployability of micro frontends is key. This reduces the scope of any given deployment, which in turn reduces the associated risk.

In your case,

Check these links;

Upvotes: 3

Related Questions