npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dum-packer

v0.1.8

Published

Simple Web Project Packer

Downloads

131

Readme

dum-packer

A dumb way to pack a web application into a daft little bundle.

This package is designed to bundle parts of a web-based project into a single HTML file that is readable and straight-forward. Effectively, it just slots your HTML/code/styling into their respective areas.

Features

  • Single file output
  • Automatic translation to HTML/CSS/JS
  • Minification & formatting/beautifier
  • Development server/hot reload

Supported Languages

Markdown/Templates

  • HTML
  • PUG

Styling

  • CSS
  • SCSS/Sass

Code

  • JavaScript
  • TypeScript

Caveats

  • If you decide to use this, remember that it's dumb.
  • Use ESM, don't use default exports.
  • No contents from node_modules will be bundled in the project.
    • Import from a CDN & use the import map option for external modules when possible.
  • Include the tag in the template page.
  • The built project will be emitted to the current directory

Usage

Dumb simple: import the DumPackerProject class, instantiate it with your project's options, call .run() or .build(), and you're golden.

Module resolution at runtime is handled by dum-imex. Any import or export calls will be converted to __dum_import and __dum_export calls. A global object, __dum_scope, is used to hold exported items. Defaults and side-effect imports will be omitted.

The packer will generate a dependency tree from files indicated in code, translate all code files and local dependencies, transform them into dum-imex format, toss'em in separate closures, then append them in separate script tags to the end of the document's body.

Adding the comment __dum_omit will exclude the line from the output.

Adding the comment __dum_ignore will prevent modification from the dum-imex transform.

Example

File structure

root_dir/
    src/
        index.pug
        index.ts
        style.scss
    main.js

main.js

import { DumPackerProject } from 'dum-packer';

const project = new DumPackerProject({
	// required; project/output file name
	name: 'dum-packer-example',

	// required; base for project's files
	// used as base path for modules
	base_dir: 'src/',

	// required; single file
	page: 'src/index.pug',
	// optional; single file or array
	style: ['src/style.scss'],
	// optional; single file or array
	code: 'src/index.ts',

	// optional; html import map script type w/o scopes
	import_map: {
		package: 'CDN url',
	},

	build_options: {
		// optional; minify.Options, minifies when not undefined
		minify: {},
		// optional; prettier.Options, beautifies when not undefined & not minified
		beautify: {},

		// optional; any value besides undefined will watch for file changes, rebuild when triggered
		watcher: {
			watcher_dir: 'src/', // optional; directory to watch. default: project.base_dir
		},

		// optional; any value besides undefined will serve project
		server: {
			hostname: 'localhost', // optional. default: localhost
			port: 5888, // optional. default: 5174
			server_dir: 'src/', // optional; directory to serve. default: project.base_dir
			hot_reload: true, // optional; enable hot reload, requires watcher to be started
		},
	},
});

// builds project, starts watcher/server
// if neither set, just build synchronously
project.run();

// to just build project (async)
// note that build options will be respected; if set to hot reload, related code will be inserted, but the watcher/server will not be run
project.build();

// output: root_dir/dum-packer-example.html

Future Plans

I'll probably keep tinkering with this whenever I find things to tweak or features to add. I'll (try to) keep an eye on the repo, so you're encouraged to lodge any bugs/suggestions/complaints/comments/concerns there.

(Same thing if there's any metadata for this package/repo that doesn't seem right; this is my first published package.)

Things that are likely:

  • Option to disable dum-imex system and/or closures
    • Former will probably just be based on if it's needed or not
  • Option to determine where built project file goes (it doesn't feel necessary; this packer is dumb)
  • More options for ~~minification, server,~~ other obfuscated elements

Things that are less likely, but not unlikely:

  • Loader system to allow for more supported languages
  • CLI tool

Things that are unlikely:

  • Router/single-page application system (you probably want another packer if you're looking to do this)

Things that, if I have my way, will not happen:

  • Default exports (get outta here with that)
  • Bundling modules in node_modules
  • Module systems besides ESM (unless covered via the loader system)
  • Any sort of meaningful testing