angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

No publicPath option in configuration file

Open manuelcua opened this issue 10 years ago • 36 comments

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

manuelcua avatar Sep 21 '16 16:09 manuelcua

@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

piyushchauhan2011 avatar Dec 07 '16 20:12 piyushchauhan2011

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

filoxo avatar Dec 07 '16 20:12 filoxo

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

ghost avatar Aug 30 '17 10:08 ghost

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

kuangthien avatar Nov 01 '17 04:11 kuangthien

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

filipesilva avatar Nov 01 '17 09:11 filipesilva

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

merwok avatar Nov 01 '17 14:11 merwok

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>

hpjc avatar Nov 02 '17 10:11 hpjc

These paths are the main app files, not assets like images referenced in other HTML components. https://github.com/angular/angular-cli/issues/4517#issuecomment-286238951

merwok avatar Nov 02 '17 15:11 merwok

We only process images in CSS actually. Images in HTML are not processed. The tracking issue for HTML resource support is https://github.com/angular/angular-cli/issues/3415.

filipesilva avatar Nov 02 '17 16:11 filipesilva

@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.

feng-xiao avatar Nov 28 '17 14:11 feng-xiao

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/*.

ltvan avatar Nov 29 '17 02:11 ltvan

@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.

feng-xiao avatar Dec 04 '17 15:12 feng-xiao

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

filipesilva avatar Dec 07 '17 16:12 filipesilva

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

feng-xiao avatar Dec 12 '17 14:12 feng-xiao

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

thescientist13 avatar Jun 24 '19 20:06 thescientist13

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.