简体   繁体   English

如何更改 dist 文件夹路径而不覆盖 output 文件夹中的现有文件

[英]how to change the dist-folder path without overwriting existing files in output folder

I'm using JAVA and app engine as backend and angular as frontend also I want to directly build my files using ng build and output them to my java project so I tried replacing outputPath in my angular.json file as so I'm using JAVA and app engine as backend and angular as frontend also I want to directly build my files using ng build and output them to my java project so I tried replacing outputPath in my angular.json file as so

{ {

  ...
  "options": [
    {
      "outputPath": "../../myproject/java/src/main/webapp/",
      ...
    }
  ],
  ...
}

all files are correctly placed in webapp folder but the only problem is that it overwrites the whole folder leading to loosing other project files/directories, so I have to manually place files into this directory which is what I want to avoid.所有文件都正确放置在webapp文件夹中,但唯一的问题是它会覆盖整个文件夹,导致丢失其他项目文件/目录,因此我必须手动将文件放入此目录,这是我想要避免的。

I also tried changing the base-href and try to load my files from a /dist folder.But changing base-href leads to incorrect url routing.我还尝试更改base-href并尝试从/dist文件夹加载我的文件。但是更改base-href会导致 url 路由不正确。

any solution to avoid overwriting files.任何避免覆盖文件的解决方案。

If you are manually adding files after build, then you can try writing a postbuild action that copies all those files into build folder.如果您在构建后手动添加文件,那么您可以尝试编写一个postbuild后操作,将所有这些文件复制到构建文件夹中。

File package.json :文件package.json

  "scripts": {
    "start": "ng serve",
    "build": "ng build --prod",
    "postbuild": "cp somefile ../../myproject/java/src/main/webapp/somefile",
    ...
  },

If you are on windows OS and want to do multiple actions, you may use powershell script that can be invoked as a postbuild step.如果您在 windows 操作系统上并想要执行多个操作,您可以使用powershell脚本,该脚本可以作为postbuild步骤调用。

  "scripts": {
    ...
    "postbuild": "powershell ./update-build-folder.ps1",
    ...
  },

Everytime you run npm build / yarn build , build directory will be cleaned, afterwards angular CLI will output the JS files and then all those custom files will be placed in the build directory.每次运行npm build / yarn build时,都会清理 build 目录,之后 angular CLI 将 output 生成 JS 文件,然后将所有这些自定义文件放在 build 目录中。

What version of angular-cli are you using?您使用的是哪个版本的 angular-cli? I'm able to successfully build to a directory that is outside of the angular project, which contains other files, WITHOUT those additional files getting deleted.我能够成功构建到 angular 项目之外的目录,其中包含其他文件,而不会删除这些额外的文件。 (this is with angular-cli v7.3.9) (这是 angular-cli v7.3.9)

Lastly, are you sure that some OTHER script isn't the one deleting the files in your build path?最后,您确定某些 OTHER 脚本不是删除构建路径中文件的脚本吗? (ie a backend build script) (即后端构建脚本)

...
"options": {
            "outputPath": "../custom-output/web/build-here",
            ...
},
...

Screenshots:截图:

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM