Skip to content

No publicPath option in configuration file #2276

Closed

Description

@manuelcua

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

Activity

  1. markus-heer commented on Sep 25, 2016

    @markus-heer

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

  2. manuelcua commented on Sep 28, 2016

    @manuelcua
    Author

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

  3. theDustRoom commented on Sep 29, 2016

    @theDustRoom

    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.

  4. filipesilva commented on Oct 5, 2016

    @filipesilva
    Contributor
  5. manuelcua commented on Oct 5, 2016

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

  6. theDustRoom commented on Oct 7, 2016

    @theDustRoom

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

  7. added
    P5The team acknowledges the request but does not plan to address it, it remains open for discussion
    on Oct 10, 2016
  8. filipesilva commented on Oct 10, 2016

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

  9. erhard commented on Oct 11, 2016

    @erhard

    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.

  10. naveedahmed1 commented on Oct 15, 2016

    @naveedahmed1

    Is there any update on this?

  11. 17 remaining items

  12. kuangthien commented on Nov 1, 2017

    @kuangthien

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

  13. filipesilva commented on Nov 1, 2017

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

  14. merwok commented on Nov 1, 2017

    @merwok

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

  15. hpjc commented on Nov 2, 2017

    @hpjc

    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>
    
  16. merwok commented on Nov 2, 2017

    @merwok

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

  17. filipesilva commented on Nov 2, 2017

    @filipesilva
    Contributor

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

  18. feng-xiao commented on Nov 28, 2017

    @feng-xiao

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

  19. ltvan commented on Nov 29, 2017

    @ltvan

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

  20. feng-xiao commented on Dec 4, 2017

    @feng-xiao

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

  21. filipesilva commented on Dec 7, 2017

    @filipesilva
    Contributor

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

  22. feng-xiao commented on Dec 12, 2017

    @feng-xiao

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

  23. thescientist13 commented on Jun 24, 2019

    @thescientist13

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

  24. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  25. locked and limited conversation to collaborators on Sep 9, 2019
  26. added a commit that references this issue on May 29, 2026
    9ae54b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P5The team acknowledges the request but does not plan to address it, it remains open for discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions