Ngx-admin: dist error 404 for assets in production

Created on 30 May 2017  路  7Comments  路  Source: akveo/ngx-admin

I am run production mode using "npm run build:prod:aot"
after adding base href in index.html
<base href=".">
moved dist folder into xampp htdocs folder after getting 404 Error
angularerror

Most helpful comment

@AnisAli I found another method: set the base-url path like this:
npm run build:prod --aot --base-href /QS_NG/
'/QS_NG/' is my deploy name

All 7 comments

I am having a same problem. Did u find a fix?

I am also having the same problem. I have moved dist folder into IIS.
Related Issue: https://github.com/akveo/ng2-admin/issues/1050

@raff90 @sridharan31 meanwhile dev team give any solution, i have created the gulp task for replacing all url /assets/xxxx/xxxx to ./assets/xxx/xxx. After replacing this i am not getting any errors.

gulpfile.js
var replace = require('gulp-replace');
var gulp = require('gulp');
gulp.task('templates', function(){
gulp.src(['dist/*.css','dist/*.js'])
.pipe(replace(':url(/assets', ':url(./assets'))
.pipe(gulp.dest('dist/'));
});

@AnisAli your method is work, but seems not good enough. I don't understand why change '/assets' to './assets' in src code will report error when npm run build.

@AnisAli I found another method: set the base-url path like this:
npm run build:prod --aot --base-href /QS_NG/
'/QS_NG/' is my deploy name

@dyh333 That's the correct solution, closing then.

For those of you who can't get it to work with <base href="./"> here is what worked for me:

  • I am assuming that you already can run the project with electron in dev mode, in macOS.
  • I am assuming you have already installed electron-packager.
  1. copy package.json and main.js to src/electron/ (you have to create this folder)
  2. add <base href="./"> to the src/index.html head tag
  3. add this scripts to your package.json (both of them):
scripts: {
    "packelectron-mac": "npm run build-electron-mac && npm run package-mac",
    "build-electron-mac": "ng build --env=prod --base-href ~ && cp src/electron/* dist",
    "package-mac": "electron-packager dist ProjectName --platform=darwin --electron-version=\"2.0.2\""
}

*Notice that you should use your own version of electron, mine is 2.0.2 (if you want to know the version type electron -v in the terminal)

  1. Change the variable $assets-root in src/app/theme/sass/conf/_variables.scss to this:
    $assets-root: '/ProjectName.app/Contents/Resources/app/assets';
  2. Run the packelectron-mac script, that is npm run packelectron-mac
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hoswey picture hoswey  路  3Comments

burtonator picture burtonator  路  3Comments

AZm1n picture AZm1n  路  4Comments

igorls picture igorls  路  3Comments

nsankaranarayanan picture nsankaranarayanan  路  3Comments