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

Production build path change issues - ng build

Open babupca opened this issue 8 years ago • 4 comments

OS Windows 7 x64

Versions node --version - v6.11.2 npm --version - 3.10.9

ng --version

Angular CLI: 1.5.3
Node: 6.11.2
OS: win32 x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, tsc-wrapped
@angular/cli: 1.5.3
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.3
@schematics/angular: 0.1.5
typescript: 2.3.4
webpack: 3.8.1

Steps to Reproduce Currently we are developing an internal application for our company using angular 4. We are able to build and deploy the application to the production environment. But after the build we are facing path change issues in the bundled js and css file.

Issue When doing the production build, we have to to manually add the base folder name inside main.bundle.js file style.bundle.js file - @import url(/assets/css/styles.css)

For example scenario one 1:* dashboard.component.html Local Environment -- <img src="/assets/img/no-image.png" alt="No Image" title="No Image" /> changed to
Production Environment -- <img src="**/itpuipreprod**/assets/img/no-image.png" alt="No Image" title="No Image" /> In order to change this, we manually edit the main.bundle.js file and replace with the itpuipreprod folder name every where.

I used the following command ng build --prod -aot --output-path="/itpuipreprod" --base-href="/itpuipreprod"

This command does not replace the /itpuipreprod in all the places, rather it only replaces in the component level background image in css files only, the same for the typescript file as well, please check the below code, this getScript code also does not been replaced with /itpuipreprod before the assets keyword.

 $.getScript( "/assets/scripts/value-driver.js").done(function( script, textStatus ) {
        console.log("script initialized!..." );
        $("div#page-value").initValuePage();
 });

Because of this, we could not able to create an automated build using jenkins, kindly give some suggestion or solution to overcome this issue.

Please let us know, if you require any more details, i will share you.

Thanks Bab

babupca avatar Dec 13 '17 04:12 babupca

A base HREF of /itpuipreprod and /itpuipreprod/ have different meanings. If the name (itpuipreprod) is intended to be a directory (as opposed to a file), the slash is critical.

Also, the base href is only applied by the browser to relative assets (not absolute nor root relative). Due to the usage of webpack, stylesheet assets with a root relative URL are not processed by webpack and instead the URL is augmented with a combination of the configured base HREF and deploy URL. The stylesheet root relative URL is, in essence, an escape mechanism for the URL from webpack build time processing.

clydin avatar Dec 14 '17 16:12 clydin

@babupca did @clydin's answer resolve your issue?

filipesilva avatar Jan 09 '18 14:01 filipesilva

Closing as no further feedback was provided.

alan-agius4 avatar Oct 08 '18 11:10 alan-agius4

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.