1.2.0 • Published 5 months ago

@anio-sh/bundler v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

@anio-sh/bundler

Bundles ecmascript source code into a single file with rollup.

External resources can be embedded too.

Usage

anio_bundler <project_root>

Where <project_root> must contain a file named anio_project.mjs.

This file must export either an object or a function that will resolve to an object:

export default {
	bundler: {
		entry: "src/entry.mjs",
		output: "dist/bundle.mjs"
	}
}

Multiple targets can be specified by using an array:

export default {
	bundler: [{
		entry: "src/cli.mjs",
		output: "dist/cli.mjs"
	}, {
		entry: "src/index.mjs",
		output: "dist/bundle.mjs"
	}]
}

Embedding resources

Sources (that need to be embedded inside the bundle) must be saved under: <project_root>/bundle.resources/ and can be loaded via:

import {loadResource} from "@anio-sh/bundler"

const resource_contents = loadResource("file.txt")

Note:

⚠️ loadResource is synchronous to be more versatile (i.e. so it is usable in async contexts as well).

This code would return the contents of bundle.resources/file.txt.

Embedded resources will have a unique identifier so that names won't collide with other bundles generated by @anio-sh/bundler:

globalThis.__anio_bundler_resources["64de3d40048d8948-{0}"] = JSON.parse(
	"{\"a/test.sh\":\"test\\n\"}"
);

Accessing project's package.json

It is possible to access the project's package.json in a bundle and at runtime like so:

import {loadPackageJSON} from "@anio-sh/bundler"

//
// returns live package.json contents
// OR the bundled version of it
//
const package_json = loadPackageJSON()

When bundling, the contents of the current package.json will be embedded into the bundle.

Accessing information about @anio-sh/bundler

It is possible to retrive information about the bundler in use:

import {getBundlerInformation} from "@anio-sh/bundler"

// live = true => running in "normal" mode
// live = false => running in "bundle" mode
console.log(getBundlerInformation())
1.2.0

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago

0.3.0

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.1.0

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago