Reading bauer dependencies in grunt file list

I am using grunt and I want to copy the bower dependencies when creating a production distribution

These dependencies already exist in. / components

I am creating a production directory with index.html inside and want to copy only the dependencies from the bower.json file.

I thought it would be as simple as generating a list from deps:

prodComponents = Object.keys(grunt.file.readJSON('./bower.json').dependencies) 

(which is created using a simple console.log (prodComponents)

 [ 'requirejs', 'requirejs-text', 'jquery', 'underscore-amd', 'backbone-amd', 'backbone.wreqr', 'backbone.babysitter', 'marionette' ] 

and then just copy the appropriate files:

  copy: deps: files: [ expand: true cwd: './components' src: ['./<%= prodComponents %>/*'] dest: './dev/components' ] 

This works, but copies ALL components. i.e. my file error

 Running "copy:deps" (copy) task Created 15 directories 

if i delete. /, then crash:

 Warning: Unable to read "components/Applications" file (Error code: ENOENT). Use --force to continue. 

I can't help but think that I'm either trying to be too smart, or almost there with that.

What am I doing wrong with the file specification spec?

thanks

+4
source share
1 answer

I think you are close. I would save directories with globe templates used in prodComponents :

 prodComponents = Object.keys(grunt.file.readJSON('./bower.json').dependencies).map( function(prodComponent) { return prodComponent + "/**/*"; } ); 

So prodComponents will contain:

 ["requirejs/**/*", "requirejs-text/**/*", "jquery/**/*", "underscore-amd/**/*", "backbone-amd/**/*", "backbone.wreqr/**/*", "backbone.babysitter/**/*", "marionette/**/*" ] 

And the copy configuration will be:

 copy: deps: files: [ expand: true cwd: 'components' src: '<%= prodComponents %>' dest: 'dev/components' ] 

Please note that in order for you to use prodComponents in the template in this way, you need to install it in the grunt config .

+2
source

Source: https://habr.com/ru/post/1488325/


All Articles