Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access rootPath set from gulp task from within angular application

I have the following task that build my application:

const app = new Metalsmith(config.styleguide.path.root);
app.use(
       msDefine({
           production: false,
           rootPath: '/'
       })
   );

app.use(
    msIf(
        gutil.env.config === 'release',
        msDefine({
            production: true,
            rootPath: '/styleguide/'
        })
    )
);
app.build(...);

I need to access the rootPath from within the application, eg:

import stuff from 'stuff';
export class IconCtrl ...
   ...
   _getIconPath(name: string, size: string): string {

      switch (this.version) {
        case 'current':
            return `${stuff.rootPath()}/current/icn-${name}-${size}.svg`;
        default:
            return `${stuff.rootPath()}/legacy/${name}.svg`;
      }
   }
   ...

I haven't found a clean way to do it so far. I am not sure how to access the application configuration at build time from within the app.

like image 726
Alex C Avatar asked Oct 29 '22 21:10

Alex C


1 Answers

you could use something like gulp-inject-scripts. https://www.npmjs.com/package/gulp-inject-scripts

Example

var gulp = require('gulp');
var injectScripts = require('gulp-inject-scripts');

gulp.task('inject:script', function(){
  return gulp.src('./demo/src/*.html')
    .pipe(injectScripts({
      baseDir "./demo/dist" // SET BASE DIRECTORY 
    }))
    .pipe(gulp.dest('./demo/dist'));
});
like image 77
racamp101 Avatar answered Nov 14 '22 04:11

racamp101