Need to copy dist folder to another folder after successful build Angular

Viewed 137

Actually, I want to build my project on a server. The problem is that the build process deletes the dist folder before the build complete. If any error occurs while building a project, the website goes down. I want the dist folder will delete only after a successful build. Or Move the dist folder to another folder after a successful build.

1 Answers

Actually, I am doing this to add SSR build folder(dist) to add inside of the build folder in React.js Redux.

Step 1: webpack.build.config.js

const path = require('path');
module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build/dist'),
    filename: 'bundle.js'
  },
}

Step 2. webpack.server.config.js

const path = require('path');
const webpackNodeExternals = require('webpack-node-externals');
module.exports = {
  mode: 'development',
  target: 'node',
  entry: './server/index.js',
  output: {
    path: path.resolve(__dirname),
    filename: 'server.js'
  },
}

Step 3. package.json

"scripts": {
    "start": "react-scripts start && webpack-dev-server",
    "cleanBuild": "rimraf ./build/*",
    "build": "npm run cleanBuild && set \"GENERATE_SOURCEMAP=false\" && react-scripts build",
    "server-build": "webpack --config webpack.build.config.js && webpack --config webpack.server.config.js",
    "serve:ssr": "node server.js"
  },

Step 4: Make Build

First, Build Normal npm run build. Second, build SSR npm run server-build. Third, run SSR Code & normal code by using node server.js and npm run start.

Related