webflow-bundler
v1.1.1
Published
Bundle, Minify, and Clean JS/TS files for Webflow
Readme
webflow-bundler
A Node.js tool for bundling, minifying, and cleaning JavaScript/TypeScript code so it can be easily copy-pasted into Webflow custom code blocks and pages. Use it directly in your package.json scripts for a seamless workflow. This tool streamlines preparing modern JS/TS for Webflow, ensuring compatibility, reduced file size, and easy embedding.
Features
- Bundle: Combines all imports and dependencies into a single file per entrypoint.
- Minify: Produces a minified version for optimal performance.
- HTML Wrapping: Optionally wraps output in
<script>...</script>tags for direct embedding in Webflow custom code blocks. - Console Stripping: Optionally removes all
console.*statements for cleaner production code. - TypeScript & JavaScript: Supports both
.tsand.jssource files. - Pretty Output: Outputs a prettified, readable version alongside the minified one.
Installation
Install as a dev dependency:
npm install --save-dev webflow-bundlerUsage
The most common way to use webflow-bundler is in your package.json scripts.
In package.json
Add a script:
{
"scripts": {
"bundle:webflow": "webflow-bundler --source src --output dist/js --minify --html --drop-console"
}
}Then run:
npm run bundle:webflowOptions
| Option | Alias | Description |
| ---------------- | ----- | --------------------------------------------------------------- |
| --source <dir> | -s | Source directory (default: src) |
| --output <dir> | -o | Output directory (default: dist/js) |
| --minify | | Also output a minified .min.js or .min.html version |
| --html | | Wrap output in <script>...</script> tags (for Webflow blocks) |
| --drop-console | | Remove all console.* statements from output |
Example
Bundle and minify all files in src for Webflow, outputting both pretty and minified HTML-wrapped scripts:
npm run bundle:webflow
# or, if installed globally
webflow-bundler --source src --output dist/js --minify --html --drop-consoleHow It Works
- Bundles each
.js/.tsfile with its dependencies using esbuild. - Outputs both a prettified (formatted) and optionally minified version.
- If
--htmlis set, wraps output in<script>...</script>for easy embedding. - If
--drop-consoleis set, strips allconsole.*calls.
Output
- Each source file generates a bundled output in the specified output directory, preserving relative paths.
- If
--minifyis used, a.min.js(or.min.html) file is also created. - If
--htmlis used, output files are HTML-wrapped for direct copy-paste into Webflow.
Troubleshooting
- Source directory does not exist: Make sure your
--sourcedirectory exists and contains.jsor.tsfiles. - Import errors: Currently only JS/TS imports are supported. Other asset types like CSS, images, etc. will cause a build error.
License
MIT
