Relative path to Angular 4 source files

Asked

Viewed 1,168 times

0

after creating an Angular standard application with the ng new aplicacao and inserted the libraries of Primeng, Bootstrap, Fontawesome the application runs normally through the ng server.

After rotating the ng build and move the application up on the server everything works as long as the application runs from the domain root (e.g., www.abc.com.br). If the application runs from a folder (e.g., www.abc.com.br/appteste) and adjustments are made to the paths of . js, the application loads normally but the source files (.Woff, .woff2, .ttf, .svg, .eot) are being searched at the root of the domain with this error 404.

That is, the paths of the files mentioned above are not relative to the folder that the application is running. As everything is "joined" by Webpack I do not know where I should change to modify the path of the files cited above.

Does anyone know how to fix it? I thank everyone who can help.

  • You can add the source path in your application’s main SCSS file.

2 answers

0

When you create a project with ng cli, a file is created at the root of the project: .angular-cli.json inside this file Voce has the tag styles e scripts. So Voce just need to add the broker paths in that file, for example:

"styles": [
    "../node_modules/roboto-fontface/css/roboto/sass/roboto-fontface.scss",
    "../node_modules/normalize.css/normalize.css",
    "../node_modules/font-awesome/scss/font-awesome.scss",
    "../node_modules/ionicons/scss/ionicons.scss",
    "../node_modules/bootstrap/scss/bootstrap.scss",
    "../node_modules/leaflet/dist/leaflet.css",
    "../node_modules/chartist/dist/chartist.css",
    "../node_modules/fullcalendar/dist/fullcalendar.css",
    "../node_modules/handsontable/dist/handsontable.full.css",
    "../node_modules/ng2-slim-loading-bar/style.css",
    "../node_modules/angular2-toaster/toaster.css",        
    "app/theme/theme.scss",
    "styles.scss"
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/easy-pie-chart/dist/jquery.easypiechart.js",
    "../node_modules/jquery-slimscroll/jquery.slimscroll.js",
    "../node_modules/tether/dist/js/tether.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "../node_modules/handsontable/dist/handsontable.full.js",
    "../node_modules/chroma-js/chroma.js"
  ],

0

Hello, the solution for the specific case is to set the deploy-url in the ng build command:

ng build --prod --deploy-url=/apptest/ --env=dev

Browser other questions tagged

You are not signed in. Login or sign up in order to post.