How to access rootPath set from gulp task from angular app

I have the following task that creates 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 rootPath from an application, for example:

 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 have not yet found a clean way to do this. I am not sure how to access the application configuration during build from the application.

+5
source share
1 answer

you can 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')); }); 
+2
source

Source: https://habr.com/ru/post/1274372/


All Articles