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

worker-inlinify

v1.1.3

Published

worker-inlinify transforms separate web worker script reference into inline script so there is no need to carry/deploy additional worker script file.

Downloads

14

Readme

worker-inlinify

NPM version NPM downloads MIT License

worker-inlinify transforms separate web worker script reference into inline script using syntax: new Worker(window.URL.createObjectURL(new Blob(["/* Web Worker code here */"]))).

Installation

You can install it globally to use the CLI everywhere.

npm install worker-inlinify -g

Or just install within your project.

npm install worker-inlinify --save

Command line interface

worker-inlinify is available as a global command if you installed it globally. It will read all *.js files from the current working directory and inlinify any external web worker references like new Worker("worker.js") if the external web worker script can be found.

For example, you have following files in the home directory.

  1. home/main.js

    var worker = new Worker('src/worker.js');
    var fakeWorker = new Worker('non-existing-worker.js');
    eval('new Worker("src/worker.js")');
  2. home/src/worker.js

    (function(){
        console.log('Hi from worker.js');
    })();
       

After running worker_inlinify command in home directory, the main.js will be overwritten to:

var worker = new Worker(window.URL.createObjectURL(new Blob(["(function(){\r\n    console.log(\'Hi from worker.js\');\r\n})();"])));
var fakeWorker = new Worker('non-existing-worker.js');
eval('new Worker(window.URL.createObjectURL(new Blob([\"(function(){\\r\\n    console.log(\\\'Hi from worker.js\\\');\\r\\n})();\"])))');

If you don't want to install it globally, worker-inlinify is also available from npm scripts, you can define it in a custom script like below in your package.json.

{
  "scripts": {
    "inlinify": "worker-inlinify"
  }
}

And npm run inlinify will do the same trick.

--loose

If you have the following code snippet, you would get an error: SyntaxError: Identifier 'a' has already been declared (3:4) when running worker-inlinify. This is because worker-inlinify uses Acorn as the JavaScript parser to parse your JS code and Acorn will raise a SyntaxError object when encountering a syntax error.

var worker = new Worker('src/worker.js');
let a = 'a';
let a = 'a';

You can use worker-inlinify --loose to overcome this, but it is not recommended.

workerInlinify.inlinify(source)

Description: Inlinify the given source code.

Arguments

Return value

The inlinified script.

workerInlinify.inlinifyFile(file)

Description: Inlinify the given JS file, the file must have a "js" extension name.

Arguments

Return value

No return value, the JS file will be overwritten with the inlinified result.

workerInlinify.contextPath

Description: The path where workerInlinify finds the external web worker scripts.

Type: String

Defautl value: process.cwd()

The default contextPath is the current node working directory. You can set to a custom path where workerInlinify can find the external web worker scripts.

workerInlinify.useLoose

Description: Whether to use an error-tolerant parser.

Type: Boolean

Default value: false

The default value is false. If you encounter a SyntaxError when inlinifying the script, you may either fix the Syntax error in your script or set this value to true to solve it.