y-src-pack Resource Bundler

1.0.15 · active · verified Tue Apr 21

y-src-pack is a JavaScript utility designed to bundle various resource files (like media, configuration, or data) into a single JavaScript file, making them synchronously accessible via a generated API. It supports bundling for web applications, Node.js environments, and integration with Webpack. The current stable version is 1.0.15. Unlike traditional bundlers focused primarily on JavaScript and CSS, y-src-pack emphasizes consolidating arbitrary application assets, exposing them through a customizable JavaScript variable or Node.js module. Its primary release cadence is not explicitly stated, but the package is actively maintained with considerations for future major upgrades.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `y-src-pack` to bundle resources from multiple directories and glob patterns into a single output file, making them accessible via a global JavaScript variable.

const YSrcPack = require('y-src-pack');
const path = require('path');

const projectRoot = process.cwd();
const jsname = 'myBundledResources'; // Or true for JSON, falsy for Node.js module

YSrcPack.process({
  // Collect files from a single directory
  dir: path.resolve(projectRoot, 'src/assets'),
  // Or use glob patterns for more specific file selection
  glob: [
    {
      dir: path.resolve(projectRoot, 'src/data'),
      glob: ['*.json', '**/*.txt']
    },
    {
      dir: path.resolve(projectRoot, 'src/images'),
      glob: '**/*.{png,jpg,svg}'
    }
  ],
  tgtFile: path.resolve(projectRoot, 'dist/bundled-resources.js'),
  jsName: jsname
});

console.log('Bundling process initiated. Check dist/bundled-resources.js');

view raw JSON →