bundler.macro
Bundle local JavaScript and TypeScript files with parcel.js.
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 add bundler.macro babel-plugin-macros
pnpm add bundler.macro babel-plugin-macros
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';
const bundledOutput: string = esbuildBundler('./main.ts');
Bundle files using rollup.
import { rollupBundler } from 'bundler.macro';
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';
const output: string = transpileFile('./simple.js');