如何从角度应用程序中的gulp任务访问rootPath集

Ale*_*x C 5 javascript angularjs typescript gulp metalsmith

我有以下任务来构建我的应用程序:

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(...);
Run Code Online (Sandbox Code Playgroud)

我需要访问rootPath应用程序中的from,例如:

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`;
      }
   }
   ...
Run Code Online (Sandbox Code Playgroud)

到目前为止,我还没有找到一个干净的方法.我不确定如何在应用程序内构建时访问应用程序配置.

rac*_*101 2

你可以使用类似 gulp-inject-scripts 的东西。 https://www.npmjs.com/package/gulp-inject-scripts

例子

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'));
});
Run Code Online (Sandbox Code Playgroud)