Including current year in Header file with Gulp Header

后端 未结 2 1306
梦毁少年i
梦毁少年i 2021-01-18 17:32

Is there anyway to print out the current year in a header file using Gulp Header?

Here\'s an example of what I\'d like to do:

var banner = [\'/**\',
         


        
相关标签:
2条回答
  • 2021-01-18 18:19

    Looks like gulp uses lodash templates; you should be able to include arbitrary JavaScript:

    var banner = ['/**',
      ' * Copyright (c) <%= new Date().getFullYear() %> Cofey',
      ' * <%= pkg.name %> - <%= pkg.description %>',
      ' * @version v<%= pkg.version %>',
      ' * @link <%= pkg.homepage %>',
      ' * @license <%= pkg.license %>',
      ' */',
      ''].join('\n');
    
    0 讨论(0)
  • 2021-01-18 18:35

    Since Node.js 4.4.1 ES6 template literals are supported:

    var banner = `/**
     * Copyright (c) ${new Date().getFullYear()} Cofey
     * ${pkg.name} - ${pkg.description}
     * @version v${pkg.version}
     * @link ${pkg.homepage}
     * @license ${pkg.license}
     */\n`;
    
    0 讨论(0)
提交回复
热议问题