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

No publicPath option in configuration file #2276

Closed
manuelcua opened this issue Sep 21, 2016 · 36 comments
Closed

No publicPath option in configuration file #2276

manuelcua opened this issue Sep 21, 2016 · 36 comments
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion

Comments

@manuelcua
Copy link

manuelcua commented Sep 21, 2016

I´ve searched in the source but there´s no way of setting the "publicPath" of my application

It should be inside the webpack output configurations but looking at angualr-cli source it´s not available.

For me it is crucial because I prepend /static/dist/ to load javascript and assets on my app.

I´m using NG version 1.0.0-beta.15

I´m using Django as Server and only doing watch on ng build and Django puts it´s static files in /static/ folder and maps the base URL to a template index.html file so the hrefs in the index files are not relative to the static folder and gets a 404 error.

All of this gets solved if I could add the publicPath configuration in angular-cli.json or environment files

@markus-heer
Copy link

This would be great! My build isn't located on the server's base folder, but in the public folder. So after every build, i have to change the strings in my index.html manually again...

@manuelcua
Copy link
Author

Also, with this integration we can use the standard way of Lazy Loading modules with the router.

@theDustRoom
Copy link

Definitely +1 for this config option; our test and production servers use a subdirectory so having publicPath support is necessary for us but we'd only want it to be used when using the --prod flag during build or serve.

@filipesilva
Copy link
Contributor

You can use the --base-href flag for this: https://github.com/angular/angular-cli#base-tag-handling-in-indexhtml

@manuelcua
Copy link
Author

@filipesilva : This does not solve de problem, the --base-href is only to provide root point for the Angular Route Path, not for the root of static files.

@theDustRoom
Copy link

@filipesilva I agree with @manuelcua as this is a separate config option for Webpack.

The publicPath specifies the public URL address of the output files when referenced in a browser. For loaders that embed <script> or tags or reference assets like images, publicPath is used as the href or url() to the file when it's different than their location on disk (as specified by path). This can be helpful when you want to host some or all output files on a different domain or on a CDN. The Webpack Dev Server also uses this to determine the path where the output files are expected to be served from. As with path you can use the [hash] substitution for a better caching profile.

@filipesilva filipesilva reopened this Oct 10, 2016
@filipesilva filipesilva added type: enhancement P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Oct 10, 2016
@filipesilva
Copy link
Contributor

Ok, seems I misunderstood it's use. I'd be happy to review a PR for this, but bear in mind it should have a test.

@erhard
Copy link

erhard commented Oct 11, 2016

found out that js File loading is depending on browser IE Edge output
image

As you can see from the screenshot IE trys to load from two places, despite only
one is defined in the index.html

<script type="text/javascript" src="ang/inline.js"></script>
<script type="text/javascript" src="ang/styles.bundle.js"></script>
<script type="text/javascript" src="ang/main.bundle.js"></script>

If I add "apollo" to the path than IE seaches in apollo/apollo/ang/.....

While the other browser search at one place. When I write there <script type="text/javascript" src="apollo/ang/main.bundle.js"></script> it take the file from there. While IE would make "apollo/apollo/ang/main.bundle.js"
The workaround is to make the index conditional.

The solution could be a templating where the index template is written by the developper and the %bundle% is replaced by angular-cli.

@naveedahmed1
Copy link

Is there any update on this?

@stuartwk
Copy link

any update on this?

@filipesilva
Copy link
Contributor

No one has tried to do a PR yet, so no, no update yet.

@mozqt
Copy link

mozqt commented Nov 5, 2016

I'm not experiencing any issues, but I did find this issue looking for an easy setting to separate the bundled files from distribution root folder, a custom task will do for now, fingers crossed for future.

@changLiuUNSW
Copy link
Contributor

changLiuUNSW commented Nov 25, 2016

@filipesilva PR created for publicPath support including unit test
#3285

@mwaa
Copy link

mwaa commented Nov 27, 2016

How soon to have the PR merged? Need publicPath

@rsnj
Copy link

rsnj commented Nov 27, 2016

I need it as well. We can't store our javascript assets in the root of our server.

@filoxo
Copy link
Contributor

filoxo commented Dec 2, 2016

Since changeLiuUNSW's PR is still pending, I found a temporary solution in the webpack docs for outputPath. It suggests that you can add __webpack_public_path__ in your app's entry file, which is main.ts for anyone using the cli. So then my entire main.ts looks something like this:

import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app';

declare let __webpack_public_path__: any;
__webpack_public_path__ = "https://cdn.somewhe.re/";

if (environment.production) {
    enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

I realize this workaround should (hopefully) only be valid until a PR that enables publicPath is merge.

EDIT: Added variable declaration per below comment.

@piyushchauhan2011
Copy link

Hi @filoxo , I tried to do the same as above, but still the script tags and link tags in dist/index.html are not prefixed with the __webpack_public_path__ . Also, noticed that it outputs a warning of somekind while we do ng build --prod. Hence, I decalred the __webpack_public_path__ variable like declare var __webpack_public_path__: any; . Would be good to have your feedback on this.

@filoxo
Copy link
Contributor

filoxo commented Dec 4, 2016 via email

@piyushchauhan2011
Copy link

Hmm, my use case is because we are trying to serve the dist/ folder using nginx but with a sub-url , the script, link and assets are not prefixed with that sub-url and fails to load.

I checked the the index.html but it doesn't prepend the sub-url even when we do __webpack_public_path__, don't know why.

@filoxo Is your script and link are prefixed with the cdn path correctly ?

@filoxo
Copy link
Contributor

filoxo commented Dec 4, 2016

I don't use the generated index.html because my backend is Java based. Setting the publicPath would only be used after the index file has been served because it's included within the bundle. That said, I don't think that what you're attempting to accomplish would be achieved by setting the publicPath but I'm no expert with webpack so perhaps I'm wrong.

@piyushchauhan2011
Copy link

piyushchauhan2011 commented Dec 7, 2016

@filoxo Hmm, I've now shifted to parsing out index.html to add necessary changes using python and bs4 https://www.crummy.com/software/BeautifulSoup/bs4/doc/ . Not the prettiest but works for now. Looking forward to the inclusion of publicPath in angular-cli

@filoxo
Copy link
Contributor

filoxo commented Dec 7, 2016

@piyushchauhan2011 are you sure you're not just overlooking setting the baseUrl? What you're attempting to do is unrelated to publicPath.

@hansl hansl closed this as completed in 0ce64a4 Dec 29, 2016
MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this issue 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
@ghost
Copy link

ghost commented Aug 30, 2017

What's the latest on this issue, any PR yet or a work around?

@kuangthien
Copy link

Nothing change until now :(
I am using the latest Angular CLI :'(

@filipesilva
Copy link
Contributor

The --deploy-url flag (that does what --public-path does for webpack) has been around for a while: https://github.com/angular/angular-cli/wiki/build

@merwok
Copy link

merwok commented Nov 1, 2017

Again, deploy-url doesn’t change static assets paths, which publicPath does.

@hpjc
Copy link

hpjc commented Nov 2, 2017

I just tested --deploy-url to add public/static as a prefix for the src path and it worked as expected.

command:
ng build --deploy-url public/static

output:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Angular2testapp</title>
        <base href="/">
    
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
        <app-root></app-root>
        <script type="text/javascript" src="public/static/inline.bundle.js"></script>
        <script type="text/javascript" src="public/static/polyfills.bundle.js"></script>
        <script type="text/javascript" src="public/static/styles.bundle.js"></script>
        <script type="text/javascript" src="public/static/vendor.bundle.js"></script>
        <script type="text/javascript" src="public/static/main.bundle.js"></script>
    </body>
</html>

@merwok
Copy link

merwok commented Nov 2, 2017

These paths are the main app files, not assets like images referenced in other HTML components.
#4517 (comment)

@filipesilva
Copy link
Contributor

We only process images in CSS actually. Images in HTML are not processed. The tracking issue for HTML resource support is #3415.

@feng-xiao
Copy link

@filipesilva I'm using cli 1.6.0-rc.0, have set deploy-url to 'assets' in both command line and angular-cli.json. The bundles are prefixed with 'assets' in index.html, but bundle files not copied to the deploy-url folder - assets.

@ltvan
Copy link

ltvan commented Nov 29, 2017

Yeah, this fixed my problem. We set output path to 'bundles', and deploy-url to 'bundles' as well. The entry point is MVC action from URL /app/ which loaded view from bundles/index.html, so the actual URL (and base href) should be /app/, while the assets are loaded from /bundles/*.

@feng-xiao
Copy link

@filipesilva why do I get following error when I'm setting absolute url (http://...) to deploy-url parameter?

--deploy-url and/or --base-href contain unsupported values for ng serve. default serve path of '/' used. use --serve-path to override.

I need to set absolute path to that parameter to support MVC integration.

@filipesilva
Copy link
Contributor

@feng-xiao that sounds like a bug. Can you open a new issue for is to look at?

@feng-xiao
Copy link

@filipesilva Hi filipesiva, I entered the issues in #8847

@thescientist13
Copy link

thescientist13 commented Jun 24, 2019

@hpjc
Looks like that fix works for me, good call!

@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.