<%= yeoman.app %> and <%=yeoman.dist

2019-03-08 22:37发布

I often see in some example gruntfiles the use of <%= yeoman.app %> and <%= yeoman.dist %> environment variables. I haven't used this myself but where do those variables get derived from?

Also, is it possible to override those variables? Does one need to have yeoman in order to use those particular environment variables?

I've read through the documentation and the FAQ. Are there resources that discusses this more?

1条回答
做自己的国王
2楼-- · 2019-03-08 23:01

Where do those variables get derived from?

Starting broadly, read the Gruntfile example as it starts to address the <%= variable %> syntax. If you are new to Grunt, bookmark that page as there's stuff there that doesn't seem important at first but will be useful on repeated reading.

More specifically, yeah...those are from a Yeoman generator. For example, if I run the latest generator-angular, the Gruntfile.js it produces includes this bit of code:

yeoman: {
  // configurable paths
  app: require('./bower.json').appPath || 'app',
  dist: 'dist'
}

So you can see, at least from the generator I used, that <%= yeoman.app %> will default to a directory called 'app' and <%= yeoman.dist %> will point to 'dist'. If I pasted the entire Gruntfile the generator created for me, you would also see these are used by many of the tasks that build and test the app.

As you can imagine (and you see in the Gruntfile example) this isn't restricted just to yeoman because is part of Grunt, so you can use this to keep your Gruntfile clean and DRY.

Is it possible to override those variables?

Yes. The code I referenced above could be changed so that the app and dist pointed to different locations. Doing this with an app created by a yeoman generator could cause more work than it is worth. The whole point of yeoman generators is to automate work so you don't have to fiddle with these things. You get a boilerplate setup every time you use a generator.

...unless you are writing your own generator or an app from scratch and are 'borrowing' bits from a generator and then yeah, you could set them to whatever is important for your app.

Does one need to have yeoman in order to use those particular environment variables?

No, but I don't see any reason to use the name 'yeoman' if you are building an app from scratch. If you are using a yeoman generated app, I don't see the reason to change it.

查看更多
登录 后发表回答