Dynapack
raw JSON → 0.4.11 verified Sat Apr 25 auth: no javascript abandoned
A JavaScript module bundler and client-side loader that constructs a minimal set of bundles for dependency graphs with both static and dynamic dependencies. Version 0.4.11 (alpha, last release 2017) supports CommonJS static requires and node-ensure dynamic declarations, targeting isomorphic apps. Unlike Browserify or Webpack, it handles the 'dynamic dependency diamond' by ensuring each module is in exactly one bundle and dynamic requests deliver only the required static subgraph. Works on Node.js and in browsers via generated bundles.
Common errors
error Cannot find module 'node-ensure' ↓
cause node-ensure is not installed but required for dynamic dependencies.
fix
npm install node-ensure
error dynapack is not defined ↓
cause Using import instead of require in Node.js.
fix
Use const dynapack = require('dynapack');
error SyntaxError: Unexpected token ↓
cause ES module syntax used; dynapack only parses CommonJS.
fix
Rewrite to CommonJS: var x = require('module');
error No bundles generated ↓
cause Entry file does not exist or path incorrect.
fix
Check that the mainPath resolves to a valid .js file.
Warnings
deprecated Package is alpha, abandoned, and not maintained since 2017. ↓
fix Consider Webpack, Rollup, or Parcel for modern bundling.
gotcha Dynamic dependencies require node-ensure and a specific string comment syntax. ↓
fix Use the exact pattern: var __m = './path' /*js*/; followed by ensure([__m], cb).
gotcha Bundles are not minified; you must run an external minifier like uglify-js. ↓
fix Pipe bundle source through uglify-js: uglifyjs bundle.js -c -m -o bundle.min.js
breaking No ESM support; cannot import/export ES modules. ↓
fix Use CommonJS require() syntax only.
gotcha The API callback provides bundles array; each has .id, .source, and .dependencies. No promise version. ↓
fix Use the callback pattern or promisify manually.
Install
npm install dynapack yarn add dynapack pnpm add dynapack Imports
- dynapack wrong
import dynapack from 'dynapack';correctconst dynapack = require('dynapack'); - ensure wrong
import ensure from 'node-ensure';correctvar ensure = require('node-ensure'); - global wrong
import { dynapack } from 'dynapack/client';correct// In browser bundle, dynapack injects modules into global scope
Quickstart
const dynapack = require('dynapack');
const path = require('path');
const fs = require('fs');
const mainPath = path.resolve('./main.js');
const options = { dest: './build' };
dynapack.build(mainPath, options, function(err, bundles) {
if (err) throw err;
bundles.forEach(function(bundle) {
const outPath = path.join(options.dest, bundle.id + '.js');
fs.writeFileSync(outPath, bundle.source);
console.log('Wrote ' + outPath);
});
});