Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify the auto-generated bundles path using the Angular CLI

I want to serve my Angular 2 application from a relative path, however I'm running into issues with how the angular-cli generates the index.html page.

The CLI inserts script references but because a leading slash isn't included, the html base tag doesn't prefix the requests. EX of current cli output:

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

What I want is for the CLI to allow me to customize this path. EX:

<script type="text/javascript" src="/myapp/inline.bundle.js"></script>
<script type="text/javascript" src="/myapp/vendor.bundle.js"></script>
<script type="text/javascript" src="/myapp/main.bundle.js"></script>

Is this possible with the CLI? The server that is hosting these files cannot use these default paths the way they're specified in the index.html page.

like image 212
Darcy Avatar asked Jan 10 '17 22:01

Darcy


People also ask

How bundling happens in Angular?

To understand how bundling works in an Angular app, you don't need to look further than the angular. json file. The angular. json file that is generated for your Angular app is the configuration file that is used by the underlying build system contained within the Angular CLI.

How do you solve error this command is not available when running the Angular CLI outside a workspace?

To Fix Error “This command is not available when running the Angular CLI outside a workspace Error”, Do Right-Click on yours project name in VS Code and Click “Open in Integrated Terminal” Option. It would open the project to your terminal and error would be fixed.

What does ng build do in Angular?

ng buildlink. Compiles an Angular application or library into an output directory named dist/ at the given output path.


1 Answers

You can use the parameter deploy-url param in angular-cli.json. If you put text 'app' to this param, you get paths like 'app/inline.bundle.js' in your index.html file.

like image 180
Alexander Usmanov Avatar answered Oct 23 '22 06:10

Alexander Usmanov