Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/jspacker

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/jspacker

Go Modules
Version
v1.0.0
Version published
Created
Source

jspacker

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/jspacker"

Package jspacker is a javascript packer for javascript projects.

Highlights

  • Combine multiple Javascript/Typescript modules into a single file.
  • Optional ability to allow dynamic imports.
  • Can create separate plugin scripts that can import from primary script.

Usage

package main

import (
	"fmt"
	"io/fs"

	"vimagination.zapto.org/javascript"
	"vimagination.zapto.org/jspacker"
	"vimagination.zapto.org/parser"
)

func main() {
	files := map[string]string{
		"/main.js":      `import fn from './lib/utils.js'; const v = 2; console.log(v + fn())`,
		"/lib/utils.js": "export default () => 1;",
	}
	loader := func(file string) (*javascript.Module, error) {
		src, ok := files[file]
		if !ok {
			return nil, fs.ErrNotExist
		}

		tk := parser.NewStringTokeniser(src)

		return javascript.ParseModule(&tk)
	}

	script, err := jspacker.Package(jspacker.File("/main.js"), jspacker.NoExports, jspacker.Loader(loader))
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s", script)
	}

	// Output:
	// const b_default = () => 1;
	//
	// const a_v = 2;
	//
	// console.log(a_v + b_default());
}

Command

Includes command vimagination.zapto.org/jspacker/cmd/jspacker to combine multiple Javascript or Typescript files:

The jspacker command accepts the following flags

  -b string     js base dir
  -e            keep primary file exports
  -i value      input file
  -n            no exports
  -o string     output file (default "-")
  -p            export file as plugin

Command Example

The following command will bundle main.ts and all of its imports into a single file, combined.js.

jspacker -i /main.ts -n -o combined.js

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/jspacker

FAQs

Package last updated on 11 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts