I would like to use angular-cli with asp.net core and I need to know how I can change the path of the dist folder
The dist folder is the build folder which contains all the files and folders which can be hosted in the server. The dist folder contains the compiled code of your angular application in the format of JavaScript and also the required HTML and CSS files.
You could simply delete the folder manually then build again.
After coding our Angular apps using TypeScript, we use the Angular CLI command to build the app. ng build command compiles the application into an output directory and the build artifacts will be stored in the dist/ directory.
For Angular 6+ things have changed a little.
Cli setup is now done in angular.json (replaced .angular-cli.json) in your workspace root directory. The output path in default angular.json should look like this (irrelevant lines removed):
{
"projects": {
"my-app-name": {
"architect": {
"options": {
"outputPath": "dist/my-app-name",
Obviously, this will generate your app in WORKSPACE/dist/my-app-name. Modify outputPath if you prefer another directory.
You can overwrite the output path using command line arguments (e.g. for CI jobs):
ng build -op dist/example
ng build --output-path=dist/example
S.a. https://angular.io/cli/build
Setting the output path, will tell angular where to place the "compiled" files but however you change the output path, when running the app, angular will still assume that the app is hosted in the webserver's document root.
To make it work in a sub directory, you'll have to set the base href.
In angular.json:
{
"projects": {
"my-app-name": {
"architect": {
"options": {
"baseHref": "/my-folder/",
Cli:
ng build --base-href=/my-folder/
If you don't know where the app will be hosted on build time, you can change base tag in generated index.html.
Here's an example how we do it in our docker container:
entrypoint.sh
if [ -n "${BASE_PATH}" ]
then
files=( $(find . -name "index.html") )
cp -n "${files[0]}" "${files[0]}.org"
cp "${files[0]}.org" "${files[0]}"
sed -i "s*<base href=\"/\">*<base href=\"${BASE_PATH}\">*g" "${files[0]}"
fi
The more current way of this is to update the outDir
property in angular.json
(called .angular-cli.json
in old Angular CLI versions).
The ng build
command argument --output-path
(or -op
for short) is still supported also, which can be useful if you want multiple values, you can save them in your package.json
as npm scripts.
Beware: The
.angular-cli.json
property is NOT calledoutput-path
like the currently-accepted answer by @cwill747 says. That's theng build
argument only.It's called
outDir
as mentioned above, and it's a under theapps
property.
.
(December 2017)
1-year after adding this answer, someone added a new answer with essentially same information, and the Original Poster changed the accepted answer to the 1-year-late answer containing same information in the first line of this one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With