Compack Web Component Bundler
raw JSON →Compack is a command-line interface (CLI) tool designed to bundle Web Components by consolidating their individual HTML, CSS, and JavaScript files into a single distributable HTML file. This approach aimed to facilitate the packaging and distribution of components that could then be imported into web applications using HTML Imports. The package is currently at version 0.1.10. Given its last commit was approximately eight years ago and its core reliance on HTML Imports (which have been deprecated and removed from modern browsers), the project is no longer actively maintained and its output is not directly usable in contemporary web development without significant polyfilling or refactoring. Its key differentiator, the use of HTML Imports for component integration, is now a critical limitation.
Common errors
error command not found: compack ↓
compack globally using npm install -g compack. error Error: Cannot find module 'component.json' or 'components.json' ↓
compack --create or that a valid component.json file exists in the current working directory. error Failed to load resource: net::ERR_FILE_NOT_FOUND (when loading .html or .js) ↓
compack --server or ensure all file paths in your test HTML are correct relative to the location of the bundled component and polyfill scripts. Warnings
breaking The primary output of Compack relies on HTML Imports (<link rel="import">), which have been deprecated and removed from all major modern browsers (e.g., Chrome 73+). This makes components bundled by Compack largely unusable in current web environments without substantial polyfilling or refactoring to use ES Modules. ↓
deprecated The project appears to be abandoned, with no active development or updates since 2018. The last published version is 0.1.10. This implies no support for newer Web Component specifications or modern JavaScript features. ↓
gotcha The `--server` option starts a development server on `http://localhost:8181`. This port might conflict with other local services or development servers. ↓
Install
npm install compack yarn add compack pnpm add compack Imports
- Compack CLI
npm install -g compack compack --help
Quickstart
npm install -g compack
# Create boilerplate for a new component
compack --create my-first-component
# Navigate into the component directory
cd my-first-component
# Install any component-specific dependencies (if package.json exists)
npm install
# Build and bundle the component into a single HTML file
compack
# Start a development server with live reload
compack --server
# To use the component in an HTML file (note: relies on deprecated HTML Imports)
// Add a test.html file in the parent directory of 'my-first-component.html'
// and ensure webcomponents.min.js polyfill is accessible.
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing My Component</title>
<script src="webcomponents.min.js"></script>
<link rel="import" href="./my-first-component/my-first-component.html">
</head>
<body>
<my-first-component></my-first-component>
</body>
</html>
*/