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

@herberttn/bytenode-webpack-plugin

v2.3.1

Published

Compile JavaScript into bytecode using bytenode

Downloads

1,023

Readme

@herberttn/bytenode-webpack-plugin

ci coveralls npm license

Compile JavaScript into bytecode using bytenode.
Inspired by bytenode-webpack-plugin.

Install

npm install --save @herberttn/bytenode-webpack-plugin

Supported versions

  • node v14+ (this plugin is published in ES2020 CommonJS syntax at the moment)
  • webpack v5.x

Supported features

  • electron-forge with caveats
  • webpack
    • :heavy_check_mark: entry as a string (e.g., entry: 'src/index.js')
    • :heavy_check_mark: entry as an array (e.g., entry: ['src/index.js'])
    • :heavy_check_mark: entry as an object (e.g., entry: { main: 'src/index.js' })
    • :heavy_check_mark: entry middlewares (e.g., entry: ['src/index.js', 'webpack-hot-middleware/client'])
    • :x: entry.*.filename (e.g., entry: { main: { filename: 'index.js' } })
    • :heavy_check_mark: Dynamic output.filename (e.g., output: { filename: '[name].js' })
    • :x: Static output.filename (e.g., output: { filename: 'index.js' })

Usage

import { BytenodeWebpackPlugin } from '@herberttn/bytenode-webpack-plugin';

// webpack options
module.exports = {
  // ...

  plugins: [
    // using all defaults
    new BytenodeWebpackPlugin(),

    // overriding an option
    new BytenodeWebpackPlugin({
      compileForElectron: true,
    }),
  ],
};

Options

type FileMatcherIntent = string | RegExp; // glob or regex

interface Options {
  compileAsModule: boolean;      // wraps the code in a node module
  compileForElectron: boolean;   // compiles for electron instead of plain node
  debugLifecycle: boolean;       // enables webpack hooks lifecycle logs
  exclude?: FileMatcherIntent[]; // prevents assets from being compiled, accepts glob and regex
  include?: FileMatcherIntent[]; // filter assets to compile, accepts glob and regex
  keepSource: boolean;           // emits the original source files along with the compiled ones
  preventSourceMaps: boolean;    // prevents source maps from being generated
}

Globs are handled using picomatch

Default options

new BytenodeWebpackPlugin({
  compileAsModule: true,
  compileForElectron: false,
  debugLifecycle: false,
  keepSource: false,
  preventSourceMaps: true,
})

Examples

Sample projects can be found in the examples directory.

Caveats

electron-forge support

main process

You may need to change the default entry and output configurations. Probably something like this:

webpack.main.config.js
-  entry: './src/index.ts',
+  entry: {
+    index: './src/index.ts',
+  },
+  output: {
+    filename: '[name].js',
+  },
+  target: 'electron-main',
renderer process

You will probably run into missing node core modules. Should probably be fixed by something like this:

webpack.renderer.config.js
+  target: 'electron-renderer',
preload process

You may need to change the default entry and output configurations. Probably something like this:

webpack.preload.config.js
-  entry: './src/preload.ts',
+  entry: {
+    preload: './src/preload.ts',
+  },
+  output: {
+    filename: '[name].js',
+  },
+  target: 'electron-preload',
package.json
  "@electron-forge/plugin-webpack",
  {
    "mainConfig": "./webpack.main.config.js",
    "renderer": {
      "config": "./webpack.renderer.config.js",
      "entryPoints": [
        {
          "html": "./src/index.html",
          "js": "./src/renderer.ts",
          "name": "main_window",
+         "preload": {
+           "config": "webpack.preload.config.js"
+         }
        }
      ]
    }
  }

Missing node core modules

If you run into a webpack error similar to the one below, it's because bytenode requires some of node's code modules to properly do its job, and only you can decide the best way to provide them given your configuration.

Three possible solutions:

  • Set webpack's target to node
  • Set webpack's target to an appropriate electron-* target, when compiling for electron
  • Provide polyfills for the necessary modules

Other solutions may exist.

Error example:

ERROR in ../../node_modules/bytenode/lib/index.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '../../node_modules/bytenode/lib'
 @ ./src/renderer.loader.js 1:0-19

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "vm": require.resolve("vm-browserify") }'
	- install 'vm-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "vm": false }
 @ ./src/renderer.loader.js 1:0-19

Contributors