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

inline-import

v1.2.4

Published

A tool for inlining file imports.

Downloads

396

Readme

Inline Import

Build status npm version Dependencies

A tool that inlines custom file imports.

Use Case

Instead of loading external files during runtime, you may wish to integrate the raw file contents directly into your JavaScript files during build time. This tool allows you to use the native import syntax to include any data:

import data from "./data.png";

The type of the imported file can be anything. You only need to specify a preferred encoding for each file type.

Installation

npm install inline-import

Usage

Command Line Interface (CLI)

The command line tool can be invoked using the inline-import command. It requires a configuration in which the source paths and the options are specified. You can decide whether you want to provide the configuration via package.json or as a standalone file.

If there is no configuration in package.json, the tool will look for a configuration file with the default name .inline-import.json in the current working directory.

inline-import -c config/inline-import.json

Affected files will automatically be copied into a backup directory before they are modified. You can restore the original files by using the --restore option.

| Option | Shorthand | Description | |-----------|-----------|-------------------------------------------| | --config | -c | Specifies an alternative config path | | --backup | -b | Only copies files into a backup directory | | --restore | -r | Restores files from the backup directory |

JavaScript API

The immediate inlining process is destructive. Affected files will be changed permanently.
To inline your file imports, you need to specify the path to the JavaScript file that should be modified. Additionally, you need to define the extensions of the relevant import statements.

text.txt

hello world

index.js

import component from "module";
import text from "./text.txt";

inline.js

import InlineImport from "inline-import";

InlineImport.transform("index.js", {

	extensions: {
		".txt": "utf8"
	}

}).then(modified => {

	console.log(modified ? "Success!" : "Nothing changed");

}).catch(console.error);

index.js (inlined)

import component from "module";
const text = "hello world";

Options

  • Command line exclusive:
    • You must specify a source path or a list of paths under src. Glob patterns are supported.
    • An alternative backup path may be specified. The default path is .backup.
  • You may define a specific encoding for the JavaScript files that will be processed. Use one of the possible encoding values specified in node's Buffer class. The default encoding is utf8.
  • Only imports with matching file extensions will be considered. Each extension must define its own encoding.
  • If, for some reason, you don't want to use the const statement, set useVar to true.

.inline-import.json

{
	"src": ["src/**/*.js"],
	"backup": "path/to/backup",
	"encoding": "utf8",
	"useVar": true,
	"extensions": {
		".html": "utf8",
		".png": "base64"
	}
}

package.json

{
	"inlineImport": {
		"src": "src/**/*.js",
		"extensions": {}
	}
}

inline.js

InlineImport.transform(filePath, {
	encoding: "utf8",
	useVar: true,
	extensions: {}
}).catch(e => console.error(e));

Build Tool Integration

Contributing

Maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.