samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.44k stars 297 forks source link

Use readYAML instead of readJSON with Grunt (suggestion) #69

Open ghost opened 8 years ago

ghost commented 8 years ago

Regarding the chapter "Asset processing with Grunt". Instead of creating an all.json file, there is a benefit to creating a YAML file instead. The benefit is that comments are allowed in a YAML file, but not in JSON.

In your Gruntfile.js you can do this:

'web/js/all.js': grunt.file.readYAML('assets/js/all.yml')

instead of this:

'web/js/all.js': grunt.file.readJSON('assets/js/all.json')

The all.yml YAML file should look like this:

- vendor/bower/jquery/dist/jquery.js
- vendor/bower/bootstrap/dist/js/bootstrap.js
- vendor/yiisoft/yii2/assets/yii.js
- vendor/yiisoft/yii2/assets/yii.validation.js
- vendor/yiisoft/yii2/assets/yii.activeForm.js

So now you can do something like this, which can be really handy:

- vendor/bower/jquery/dist/jquery.js
#- not using bootstrap now, but may want to use it in the future
#- vendor/bower/bootstrap/dist/js/bootstrap.js
- vendor/yiisoft/yii2/assets/yii.js
- vendor/yiisoft/yii2/assets/yii.validation.js
- vendor/yiisoft/yii2/assets/yii.activeForm.js
samdark commented 8 years ago

Cool trick. Thanks!