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

babel-plugin-hot-swap-declarative-modules

v1.1.1

Published

Enables hot swaps for modules with declarative structures

Downloads

4

Readme

babel-plugin-hot-swap-declarative-modules

A babel plugin that enables hot swaps for declarative modules by inserting module.hot.accept() at the top of the file.

Unlike react-hot-loader or react-transform-hmr, this plugin does not aim to transition state between hot swaps. Instead, it simply aims to remove boilerplate. Works best with a code-base that consolidates state into a single location.

Installation

npm install --save babel-plugin-hot-swap-declarative-modules

Add "hot-swap-declarative-modules" to the plugins in your .babelrc:

{
  "plugins": [
    "hot-swap-declarative-modules"
  ]
}

Caveats & Explanation

The structural scan is quite naive and scan does not traverse beyond the most superficial level, so false positives are not the most difficult thing to achieve.

Currently, the scan involves a simple iteration over the root of the module and bails if it encounters anything but es2015 import/export declarations, variable declarations (including var, let and const), class declarations or function declarations.

If the iteration completes without encountering a non-declarative item, it injects a module.hot.accept call. The accept call is placed at the top of the file so that synchronous failures during evaluation of dependencies does not prevent a module from accepting further hot swaps.

An example of the language features that are inferred as declarative is

import a from './a';
export {b} from './b';

const c = 'c';

export const d = c + 'd';

export default function() {
  // ...
}

export class e extends a {
  // ...
}

An example of the language features that are inferred as non-declarative is

a();

if (b > 10) {
  // ...
}

const c = {};
c.d = 'd';

In short: conditionals, global variables, property assignments and function calls should be avoided at the root level.

Exceptions

Mindful of assisting with debugging, calls to the console object's properties are assumed to be declarative.