Grunt concat all package.json dependencies

限于喜欢 提交于 2019-12-13 01:59:57

问题


This is the first time I use grunt & npm.

My package.json contains this:

"dependencies": {
    "angular": "latest",
    "bootstrap": "latest",
    "jquery": "latest"
}

Is there a way to tell grunt: "Look at all of my dependencies, load the right files, and create one JS file, and one CSS file for distribution"?

*This is because I don't want to list all of the distribution files for every dependency.


回答1:


yes you can use grunt modules like: concat, cssmin, and sass, for concat your files in just 1.

I will try give a small explanation, but you can read more and understand using the links.

concat: https://www.npmjs.com/package/grunt-contrib-concat

cssmin: https://github.com/gruntjs/grunt-contrib-cssmin

sass: https://github.com/gruntjs/grunt-contrib-sass

on package json: insert this dependencies:

"grunt-contrib-concat": "*",
"grunt-contrib-cssmin": "*",
"grunt-contrib-uglify": "*",
"grunt-contrib-uglify": "*",

on gruntfile.js insert these blocks bellow:

load the tasks:

var tasks = [


            ,'grunt-contrib-concat'
            ,'grunt-contrib-uglify'
            ,'grunt-contrib-sass'
            ,'grunt-contrib-cssmin'

    ];

for css min:

cssmin: {
  target: {
    files: [{
      expand: true,
      cwd: 'release/css',
      src: ['*.css', '!*.min.css'],
      dest: 'release/css',
      ext: '.min.css'
    }]
  }
}

for Concat :

            var concat
            config.concat = concat = {};

            concat.dev = {
                files: {
                    "public/myapp.development.js": [
                        "with-bootstrap/public/js/vendor"
                        ,"with-bootstrap/public/js/**/*.js"
                    ]
                }
            };

for uglify:

config.uglify = {dist: {
                options: {sourceMap:"public/myapp.production.js.map"}
                ,files: {
                    "public/myapp.production.js": ["public/myapp.development.js"]
                }
            }}

I hope this helped you.



来源:https://stackoverflow.com/questions/36915222/grunt-concat-all-package-json-dependencies

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