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

effector-swc-plugin

v0.5.0

Published

SWC Plugin for Effector

Downloads

2,057

Readme

SWC Plugin for ☄️ Effector

A plugin to enhance your ☄️ Effector experience, just like effector/babel-plugin, but Speedy.

Can be used for SSR, debugging and testing in SWC-powered projects, like NextJS or Vite's react-swc plugin. Strives to be compatible with the built-in effector/babel-plugin.

[!IMPORTANT] SWC Plugins are currenlty unstable and experimental, NextJS and SWC do not follow semver in plugin compatibility. For more info, see versioning.

Get Started

[!TIP] A NextJS user? See NextJS documentation for an easy setup & versioning.

  1. Install the plugin

    Install a compatible tag of this package, and pin it.

    $ npm install effector-swc-plugin@compatible-tag --save-exact
    # or
    $ yarn add effector-swc-plugin@compatible-tag --exact
    # or
    $ pnpm add effector-swc-plugin@compatible-tag --save-exact
  2. Add the plugin to your configuration

    Add this plugin into your SWC configuration (e.g. .swcrc).

    {
      "$schema": "https://json.schemastore.org/swcrc",
      "jsc": {
        "experimental": {
          "plugins": [["effector-swc-plugin", {}]]
        }
      }
    }
    // You must specify a configuration for a plugin, even if it's empty

Now, the plugin is set up and ready for use.

🛠️ Configuration

  • addNames: boolean (default: true)

    Add name information when calling factories (like createStore or createDomain). Provides excellent debug or QoL information during development/testing, but its best to disable it when using minification.

  • addLoc: boolean (default: false)

    Add loc (unit location) information to factories' calls. Useful for debugging and when using devtools, like effector-logger.

  • debugSids: boolean (default: false)

    Add a file path and unit name to the end of generated SID. Useful for debugging SSR.

  • forceScope: boolean | { hooks: boolean, reflect: boolean } (default: false)

    When enabled, injects forceScope: true into all hooks or @effector/reflect calls, depending on your configuration.

    When forceScope is enabled, it enforces that your app always uses Scope during render. If the Scope is missing, the app will throw an error. This setting completely replaces the requirement for /scope or /ssr imports.

    More about Scope enforcement in documentation.

    • forceScope.hooks: boolean (since v0.2.0)

      hooks: true enforces that all hooks from effector-react and effector-solid, like useUnit and useList, use Scope.

    • forceScope.reflect: boolean (since v0.2.0)

      For @effector/reflect users. If enabled, this option enforces all components created with reflect library also use Scope.

      Note: Only useful for @effector/reflect@>=9.0.0. Versions lower than 9.0.0 do not support forceScope.

    • forceScope: boolean - a shorthand to enable/disable all options

  • factories: string[] (default: [])

    An array of module names or files to treat as factories. Only required for SSR.

    A number of community packages (patronum, @farfetched/core, etc.) are included by default, and do not require you to set them explicitly.

    If provided with a relative path (a path starting with ./), plugin will treat this as a local factory residing at a specified path relative to your .swcrc. These factories can be imported using relative imports in your code.

    If provided with other path, like a package name or a TypeScript alias, plugin will treat this as an exact import specifier which your code uses. You can not import this factory using a relative path.

    Relative import example:

    // file: /.swcrc
    ...
    "factories": ["./src/factory"]
    ...
    
    // file: /src/factory.ts
    import { createStore } from "effector";
    
    export const createBooleanStore = () => createStore(true);
    
    // file: /src/widget/user.ts
    import { createBooleanStore } from "../factory"
    
    const $boolean = createBooleanStore() /* Treated as a factory! */
  • transformLegacyDomainMethods: boolean (default: true)

    When disabled, stops transforming Unit creators in Domains, like domain.event() or domain.createEffect().

    Transforming such calls relies heavily on guessing, and is known to affect/break code unrelated to Effector. An alternative approach to these methods is to use domain argument in regular methods:

    const domain = createDomain();
    
    // ↓ pass domain as an argument
    const foo = createEvent({ domain });

    Disabling this option will stop adding sids and other debug information into these unit creators. Before turning it off, ensure that your code does not use domain methods.

    Further reading: You Don't Need Domains.

Known differences with effector/babel-plugin

  • No support for importName

    By default, the plugin supports effector (+ /compat), effector-root (+ /compat) and effector-logger. This should cover you in most of use cases. If you feel a need for this feature, please open an issue!

  • No support for noDefaults

    This is currently only used by library developers, and may be implemented in the future. If you feel you need this feature, please open an issue!

  • reactSsr replaced by forceScope

    reactSsr option is deprecated, as well as /scope imports. effector-react supports SSR by default since effector@23.

    If you want to enforce that Scope is never lost in your components, forceScope option in the plugin will do the trick.

Versioning

Because SWC plugins are unstable and experimental, breaking changes can happen in minor/patch releases of @swc/core or underlying swc_core Rust library.

This package will do its best and specify the correct @swc/core in its peerDependencies, so when you use the wrong version, it should say so.

To work around breaking changes, this package publishes different 'labels' for different corresponding @swc/core ranges. To choose an appropriate label, pick your @swc/core / NextJS version from the list.

Always pin your @swc/core and this plugin version for stable behavior.

Choosing the right plugin version:

  • Use a label @swc1.x.x for a pinned and specific @swc/core version.
  • Use a @latest label for the latest @swc/core (risky).

Example:

| @swc/core version | A compatible plugin label | | ------------------- | ------------------------- | | >=1.3.63 <1.3.106 | @swc1.3.63 | | >=1.3.106 <1.4.0 | @swc1.3.106 | | >=1.4.0 <1.6.0 | @swc1.4.0 | | >=1.6.0 <1.7.0 | @swc1.6.0 | | >=1.7.0 | @swc1.7.0 |

For NextJS users

See a NextJS-specific documentation for a detailed compatibility table and other info.