<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
Adds a header comment to a file and saves it to your distribution folder
add-dist-header uses the name
, homepage
, and license
from your project's package.json
file to create a header comment and prepend it to a build file.
Example header comment for a .js file:
Example header comment for a .css file:
Automatically prepending headers to distribution files is particularly handy when your build
tools are configured to remove comments (such as if "removeComments": true
in set
in tsconfig.json).
For a real-world example, see the files in the dist folder at
w3c-html-validator
1) Setup
Install
Install package for node:
$ npm install --save-dev add-dist-header
2) Usage
Call add-dist-header
from the "scripts"
section of your package.json file.
The first parameter is the source file (defaults to "build/*"
).
The second parameter is the output folder (defaults to "dist"
).
Example package.json script:
"scripts": {
"add-headers": "add-dist-header build dist"
},
Alternatively, you can run add-dist-header directly from the terminal in your project home
folder.
Example terminal command:
$ ls package.json
package.json
$ npx add-dist-header "build" "dist"
[17:13:50] add-dist-header dist/my-app.d.ts 413.11 kB
[17:13:51] add-dist-header dist/my-app.js 1,569.70 kB
The parameters are optional:
$ npx add-dist-header
[17:13:50] add-dist-header dist/my-app.d.ts 413.11 kB
[17:13:51] add-dist-header dist/my-app.js 1,569.70 kB
$ npx add-dist-header "meta/config.js"
[17:15:03] add-dist-header dist/config.js 3.91 kB
3) Version Number Substitution
In addition to prepending the header comment, add-dist-header also replaces all occurrences of
~~~version~~~
with the version number found in the package.json file.
This enables inserting the current package version number into your distribution files.
The substitution feature is disabled by setting --version
flag to false
:
"scripts": {
"add-headers": "add-dist-header --version=false build dist"
},
4) CLI Flags
Flag | Description | Values | Default |
---|
--delimiter | Characters separating the parts of the header comment. | string | ~~ |
--replace | Delete the original first line comment (if not marked ! important). | true , false | true |
--version | Substitute occurrences of ~~~version~~~ with the package.json version number. | true , false | true |
MIT License