I'm trying out Grunt and need a simple way to concatenate my modules

前端 未结 4 1182
星月不相逢
星月不相逢 2021-01-01 19:34

This is my first time using Grunt and I\'d like to have it combine all my js modules, each of which is wrapped in an immediately executing function, containing a \'use stric

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 20:13

    As of pull request 10, grunt-contrib-concat now has a footer option. Instead of an intro and an outro file, I would use a banner and a footer.

    Gruntfile.js

    concat: {
      dist: {
        src: ['src/my-lib.js'],
        dest: 'dist/<%= pkg.name %>.js',
        options: {
          banner: ";(function( window, undefined ){ \n 'use strict';",
          footer: "}( window ));"
        }
      }
    }
    

    In my opinion, this is more maintainable and allows for templating using other properties defined in your Gruntfile.

提交回复
热议问题