成功构建Angular后,需要将dist文件夹复制到另一个文件夹。

4

实际上,我想在服务器上构建我的项目。问题在于,在构建过程完成之前,构建过程会删除dist文件夹。如果在构建项目时出现任何错误,网站就会崩溃。我希望只有在成功构建后才能删除dist文件夹,或将其移动到另一个文件夹。


1
ng build --prod --output-path=other/path - guzmanoj
1个回答

1
Actually, 我正在这样做是为了将SSR构建文件夹(dist)添加到React.js Redux的构建文件夹中。
步骤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'
  },
}

步骤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'
  },
}

步骤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"
  },

步骤4:进行构建

首先,构建普通版本,运行npm run build。 其次,构建SSR版本,运行npm run server-build。 最后,通过使用node server.jsnpm run start来运行SSR代码和普通代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接