<%= yeoman.app %> and <%=yeoman.dist %> variables for a gruntfile

穿精又带淫゛_ 提交于 2019-12-03 04:30:33

问题


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:


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.



来源:https://stackoverflow.com/questions/21420593/yeoman-app-and-yeoman-dist-variables-for-a-gruntfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!