1.0.0 • Published 2 years ago

esbuild-header v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

esbuild-header esbuild-header

This plugin lets you add a header comment to the top of your build with Esbuild

Installation

$ npm install --save-dev esbuild-header

Getting Started

main.js

const date = new Date();
const currentTime = `${date.getHours()}:${date.getMintues()}:${date.getSeconds()}`;

console.log(currentTimes);

build.js

const headerPlugin = require('esbuild-header');

require('esbuild').build({
  entryPoints: ['main.js'],
  bundle: true,
  outfile: 'out.js',
  plugins: [headerPlugin()],
});

out.js

/*!
 * esbuild-header
 * A Esbuild plugin to add a header to file(s) after build
 * @author Johnie Hjelm <johnie@hjelm.im>
 * @version 1.0.0
 * Copyright 2022 MIT licensed.
 */
const date = new Date();
const currentTime = `${date.getHours()}:${date.getMintues()}:${date.getSeconds()}`;

console.log(currentTimes);

Configuration

An object containing configuration options may be passed into the plugin constructor headerPlugin

headerPlugin({
  template: '// This is my header',
  cwd: '/Users/foo/path/to/package.json',
});

The following options are available:

  • options.template, string: if specified, you can use your own header template with the use of Pupa to use data from package.json.
  • options.cwd, string: the path to a specified package.json to parse data for header. Default is closest found package.json