1.3.0 • Published 1 year ago

@sergiogc9/js-bundle v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

js-bundle

npm.io npm.io npm.io

A set of utils to easily bundle JavaScript and TypeScript projects using a common config used in my other projects.

This package uses esbuild to build the source code and tsc to generate the TypeScript definitions.

Getting started

Install it from NPM or github packages:

yarn add -D @sergiogc9/js-bundle or npm install --save-dev @sergiogc9/js-bundle.

Usage

Depending on the requirements, you can use the CLI command js-bundle or the Javascript API exported by the package.

Using the CLI

The package adds the js-bundle command to perform builds from the console, NPM scripts, pipelines, etc.

Example in console:

yarn js-bundle build --platform=node --only-bundle --only-es6

Example in NPM script, adding a script into package.json:

"scripts": {
    ...
	"build": "js-bundle build --platform=node --only-bundle --only-es6",
},

Using the JavaScript API

This package also exports a Javascript buildPackage function to programmatically perform builds. Using this option you can customize esbuild options for more complex cases.

Example for a custom build with dynamic inputs:

const { buildPackage } = require('@sergiogc9/js-bundle');

const isWatchMode = process.argv.includes('--watch');

const performBuild = async () => {
	const dynamicInputs = ['Api', 'Cache', 'Log', 'Pushover'].map(current => `src/${current}/index.ts`);

	await buildPackage({
		entryPoint: ['src/index.ts', ...dynamicInputs],
		esbuildOptions: {
			platform: 'node'
		},
		isWatchMode
	});
};

performBuild();

Configuration options

CLI options

OptionDescriptionTypeDefault
only-bundleOnly perform bundling using esbuild. No TS definition will be performed.booleanfalse
only-typesOnly generate TypeScript types. No bundling will be performed.booleanfalse
only-es6Only perform bundling with ES6 (mjs) target. No cjs bundling will be performed.booleanfalse
out-dirOutput directorystring./dist
platformEsbuild platform optionbrowser, neutral, nodebrowser
tsc-incrementalUse incremental flag for tscbooleanfalse
tsc-extend-diagnosticsUse extend diagnostics flag for tscbooleanfalse
watchUse watch modebooleanfalse

JavaScript API options

OptionDescriptionTypeDefault
entryPointSource(s) entrypoint(s)string, string[]src/index.ts
esbuildOptionsObject containing any option for the build method exported by esbuild package. Use it for overriding this packages defaults.BuildOptions{}
isWatchModeUse watch modebooleanfalse
onlyES6Only perform bundling with ES6 (mjs) target. No cjs bundling will be performed.booleanfalse
outDirOutput directorystring./dist
tscOptionsObject containing options to use with tsc.{ extendedDiagnostics?: boolean; incremental?: boolean;}{ extendedDiagnostics = false, incremental = false }
withESBuildPerform build with esbuild.booleantrue
withTSDefinitionsGenerate TS definitions.booleantrue
1.3.0

1 year ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.2-beta.1

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago