Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): add publicPath support via command and angular-cli.json #3285

Merged
merged 1 commit into from
Dec 29, 2016

Conversation

changLiuUNSW
Copy link
Contributor

@changLiuUNSW changLiuUNSW commented Nov 25, 2016

Add publicPath option for webpack.

User can specify publicPath via --deploy-url / -d from command line or add deployUrl to angular-cli.json

It can solve following issues:

  1. Change the public URL address of the output files (different from baseUrl).
  2. Manipulate the request url for chunk js files.

It is very helpful to solve resources url and route lazying load issues for those applications which have different static files paths such as ASP.NET MVC.

This should fix
#3136
#2960
#2276
#2241
#3344

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@changLiuUNSW
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@changLiuUNSW changLiuUNSW force-pushed the add-publicPath branch 7 times, most recently from c5a5523 to beac9b3 Compare November 25, 2016 23:05
@mwaa
Copy link

mwaa commented Nov 27, 2016

What's the status of this?

@naveedahmed1
Copy link

@filipesilva can this be included in next release?

@changLiuUNSW changLiuUNSW force-pushed the add-publicPath branch 2 times, most recently from 4eefd83 to 2ebdd7b Compare December 1, 2016 11:05
@changLiuUNSW
Copy link
Contributor Author

@filipesilva Could you please review this PR? Thx

@mattetti
Copy link

mattetti commented Dec 2, 2016

We also had to use a similar patch in our app, let's hope this gets merged ASAP

@changLiuUNSW changLiuUNSW force-pushed the add-publicPath branch 3 times, most recently from 0acd542 to 392caf0 Compare December 4, 2016 07:26
@mildfuzz
Copy link

mildfuzz commented Dec 5, 2016

any chance this could get merged?

@hansl hansl merged commit 0ce64a4 into angular:master Dec 29, 2016
@halfonf
Copy link

halfonf commented Jan 10, 2017

Where can I find the documentation about this ?
I need to add a deployurl in angular-cli.json and call ng build -d ??

Thx

@changLiuUNSW
Copy link
Contributor Author

@halfonf
Either way is OK

@changLiuUNSW changLiuUNSW deleted the add-publicPath branch January 11, 2017 03:53
@halfonf
Copy link

halfonf commented Jan 11, 2017

@changLiuUNSW
thx

From which version is it enabled ?

@changLiuUNSW
Copy link
Contributor Author

Not publish yet. You have to wait....

@halfonf
Copy link

halfonf commented Jan 11, 2017

@changLiuUNSW

thx I hope it will be released soon :)

@halfonf
Copy link

halfonf commented Jan 12, 2017

Hi Chang

I saw on stackoverflow that you automatized the cshtml edition.
You approach sounds great.
Can you share the gulp code you wrote to generate the json file and the mvc code integrate it ?

Thx a lot

Found a solution thx anyway

@mmc41
Copy link

mmc41 commented Jan 13, 2017

Saw that this new feature is released now. How is it actually used?
In my case, I need to serve all files in "localhost/ui" rather than "localhost/" but I can't get this feature to do that ?

@Meligy
Copy link
Contributor

Meligy commented Jan 13, 2017

@mmc41 I have the same scenario as you. I need to serve (and deploy) app as something like /all-apps/my-app/. I have achieved that using the existing --base-href option (-bh for short, works with both ng build and ng serve, although in my case I was using ng build --watch as I serve my app via IIS).

I just set it like this: ng build -bh '/all-apps/my-app/' . I have my IIS application (web server wwwroot if you may) set to the dist folder.

@mmc41
Copy link

mmc41 commented Jan 13, 2017

@Meligy I am also using -bh but could only get it to work for ng build. If I try it with ng serve, I get an error that the option is not recognised. Thus I can serve the finished distribution under a "ui/" subpath but not when I am developing and just using "ng serve"

@Meligy
Copy link
Contributor

Meligy commented Jan 13, 2017

Interesting. I believe I got it working with ng serve too. It's not on the same computer I'm posting from. I might be mistaken because I use ng build --watch instead. Sorry for that.

Maybe just setting the <base> tag in the HTML itself will work for serve. Otherwise, might have to dig in the code change in this PR.

@filipesilva
Copy link
Contributor

@mmc41 this PR is only for build, it does not add the functionality to ng serve.

When running ng build --deploy-url=deployUrl/, your app files will be in that folder (like deployUrl/main.bundle.js) and index.html will correctly reference them.

So you'd normally just run ng serve and get everything served on localhost, and then when you need to deploy you use ng build --deploy-url=deployUrl/ and copy over dist/.

@Bulan
Copy link

Bulan commented Jan 13, 2017

Is there any documentation around this somewhere?

Can I add this to be the default somewhere for ng build --prod?

@Meligy
Copy link
Contributor

Meligy commented Jan 14, 2017

The recommended way for such options as defaults is to create an npm script that calls the command with the options you need.

So, in package.json, you might have:

"scripts": {
  "start": "ng serve",
  "build:prod": "ng build -prod ....."
}

And you call it like:

npm run test:prod

@igormalyk
Copy link

@changLiuUNSW Hello, your PR is very valuable as it solves the exact same issue I have. The only thing I also need to be able to do this in dev as well with ng serve. Is there any plan to integrate this PR into ng serve?

@changLiuUNSW
Copy link
Contributor Author

changLiuUNSW commented Feb 2, 2017

@igormalyk
I believe @filipesilva has some plan to support it.
#4090

MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this pull request Feb 9, 2017
…ngular#3285)

Add publicPath option for webpack.

User can specify publicPath via `--deploy-url` / `-d` from command line or add `deployUrl` to `angular-cli.json`.

It can solve following issues:

Change the public URL address of the output files (different from baseUrl).
Manipulate the request url for chunk js files.
It is very helpful to solve resources url and route lazying load issues for those applications which have different static files paths such as ASP.NET MVC.

Fixes angular#3136
Fixes angular#2960
Fixes angular#2276
Fixes angular#2241
Fixes angular#3344
@filipesilva
Copy link
Contributor

filipesilva commented Jun 12, 2017

@igormalyk support for ng serve was added in #6112.

@Malabarba
Copy link

Hi there. Has this feature made it to a release yet?
I'm trying to use it but can't get it to work even on @angular/cli: 1.5.0-beta.2.

@filipesilva
Copy link
Contributor

@Malabarba this has been released a long time ago. If you're experiencing problems with it please open an issue with reproduction steps for us to investigate.

@Malabarba
Copy link

Sorry. I think I may have misunderstood the feature.
I ended up ejecting ngcli and configuring webpack directly, and it took a lot more configuration to get what I wanted than just the option offered by this PR.

So, I guess what I'm saying is sorry for the noise. 🙂

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.