Simple File Bundler
Simple File Bundler is a command-line utility designed to merge multiple files into a single bundle, primarily focused on concatenating CSS or JavaScript files. It operates via a configuration file (`simple-file-bundle.config.js`) located at the project root, which exports an array of bundling instructions. Each instruction specifies an output endpoint, a list of input files, an optional path prefix, and an optional separator. The package is currently at version 1.0.7, indicating a stable but likely feature-complete state with an infrequent release cadence. Its key differentiator is its minimalist approach, requiring minimal setup for basic file concatenation, contrasting with more complex bundlers that offer advanced features like module resolution, tree-shaking, or minification.
Common errors
-
Error: ENOENT: no such file or directory, open 'src/nonexistent.js'
cause One or more files specified in the `files` array or the `endpoint` path do not exist at the resolved location.fixVerify that all file paths specified in your `simple-file-bundle.config.js` are correct and the files actually exist relative to the `prefix` or the command execution directory. -
TypeError: Cannot read properties of undefined (reading 'length')
cause The `simple-file-bundle.config.js` file is either missing, empty, or does not export an array, or the exported array contains an invalid entry (e.g., missing `files` property).fixEnsure `simple-file-bundle.config.js` exists in the project root, exports a valid array, and each object in the array has at least `endpoint` and `files` properties defined.
Warnings
- gotcha The configuration file `simple-file-bundle.config.js` *must* be located at the root of your project where the `npx create-bundles` command is executed. Misplacing it will result in the bundler not finding any configurations.
- breaking The package uses CommonJS (`module.exports`) for its configuration file. If you are working in an ES module (`'type': 'module'`) project, you cannot use `export default` directly in the configuration file. You must use CommonJS syntax for `simple-file-bundle.config.js`.
- gotcha Files listed in the `files` array and the `endpoint` path are resolved relative to the `prefix` (if provided) or the directory where the command is run. Incorrect paths will lead to `ENOENT` (file not found) errors.
Install
-
npm install simple-file-bundler -
yarn add simple-file-bundler -
pnpm add simple-file-bundler
Imports
- ConfigurationArray
export default [ { /* bundle settings */ }, { /* bundle settings */ } ];module.exports = [ { /* bundle settings */ }, { /* bundle settings */ } ]; - BundleSettingObject
{ files: ['src/file.js'] }{ prefix: __dirname, endpoint: 'dist/bundle.css', files: ['src/file1.css', 'src/file2.css'], separator: '\n' } - __dirname
prefix: import.meta.url
prefix: __dirname
Quickstart
npm i simple-file-bundler
// simple-file-bundle.config.js
module.exports = [
{
prefix: __dirname,
endpoint: 'dist/style.bundle.css',
files: [
'src/style1.css',
'src/style2.css',
'src/style3.css'
]
},
{
prefix: __dirname,
endpoint: 'dist/scripts.js',
files: [
'src/index.js',
'src/superScript.js'
],
separator: '\n'
}
];
// Create some dummy files for demonstration
// src/style1.css
// body { color: red; }
// src/style2.css
// h1 { font-size: 2em; }
// src/index.js
// console.log('Hello from index.js');
// src/superScript.js
// console.log('Hello from superScript.js');
mkdir -p src dist
echo "body { color: red; }" > src/style1.css
echo "h1 { font-size: 2em; }" > src/style2.css
echo "console.log('Hello from index.js');" > src/index.js
echo "console.log('Hello from superScript.js');" > src/superScript.js
npx create-bundles
// Check outputs:
// cat dist/style.bundle.css
// cat dist/scripts.js