0.3.0 • Published 3 years ago

bundler.macro v0.3.0

Weekly downloads
50
License
MIT
Repository
github
Last release
3 years ago

bundler.macro

Bundle local JavaScript and TypeScript files with parcel.js.

Version Weekly Downloads Typed Codebase MIT License

Installation

bundler.macro is designed to be used with babel-plugin-macros to bundle or transpile files during your build step.

First, install the plugin and it's peer dependency (babel-plugin-macros). Since the macro is compiled away during the build, it should be installed as a devDependency to prevent bloating the dependency tree of the consumers of your package.

# yarn
yarn add bundler.macro babel-plugin-macros

# pnpm
pnpm add bundler.macro babel-plugin-macros

# npm
npm install bundler.macro babel-plugin-macros

Once installed make sure to add the 'babel-plugin-macros' to your babel.config.js (or .babelrc) file.

.babelrc

{
  "plugins": [
+   "macros",
    "other",
    "plugins"
  ]
}

babel.config.js

module.exports = {
  // rest of config...,
  plugins: [
+   'macros',
    ...otherPlugins,
  ]
}

Usage

Code Example

Bundle files using esbuild.

import { esbuildBundler } from 'bundler.macro';

// The file is bundled with `esbuild` and the output is provided as a string.
const bundledOutput: string = esbuildBundler('./main.ts');

Bundle files using rollup.

import { rollupBundler } from 'bundler.macro';

// The file is bundled with `rollup` and the output is provided as a string.
const bundledOutput: string = rollupBundler('./main.ts');

Transpile a file using babel

This should be used when you want to get the string output from a file, in a format that can be

import { transpileFile } from 'bundler.macro';

// The file is transpiled as a single file with babel.
const output: string = transpileFile('./simple.js');