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.
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'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With