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

nullstack-adapt-babel

v0.0.23

Published

Adapt Nullstack to Babel

Downloads

30

Readme

nullstack-adapt-babel

Fully replace Nullstack compiler (currently SWC + swc-plugin-nullstack) with Babel and it's (g)old plugins/presets system

How to use

This script can be used in two ways:

  • In the "auto" mode you just need to use with npx before your Nullstack scripts, like:
"scripts": {
  "start": "npx nullstack-adapt-babel && nullstack start",
  "build": "npx nullstack-adapt-babel && nullstack build"
}

It straight away does these things that can be fully disabled in those ways

// webpack.config.js
const useBabel = require('nullstack-adapt-babel')
const configs = require('nullstack/webpack.config')

module.exports = useBabel(configs)

In the manual mode you can configure Babel with plugins/presets

What it does in detail

When used in auto-mode with npx it does:

  • Searches for the original nullstack/webpack.config.js and replaces the module.exports there as follows:
- module.exports = [server, client]
+ module.exports = require('/full/path/to/nullstack-adapt-babel')([server, client])

Making this package to be directly called at every Nullstack run, updating the Webpack config in it's source, then it does everything exactly as manual-mode.

When used in manual-mode with custom webpack.config.js it does:

  • Searches for the original compiler loader and make it never be run:
- function swc(options, other) {
+ function swc(options, other) {return {};

This is mandatory for a environment like StackBlitz that doesn't support neither the mention of SWC

  • Checks whether it should stay disabled returning the original config if true

  • Replaces the original optimization key to use esbuild at production (see it's config here)

  • Recreates the module.rules array keeping the needed and adding Babel-related loaders

💡 Wanna dive in the code? It all starts here

How to disable the whole magic

At every run it searches for a key NULLSTACK_DEFAULT_CONFIG in your .env, like:

NULLSTACK_DEFAULT_CONFIG=true

Using if it exists, otherwise searches for the same on a key nullstack-adapt-babel in your package.json:

"nullstack-adapt-babel": {
  "NULLSTACK_DEFAULT_CONFIG": true
}

Using that value will undo everything and let Nullstack work with it's default compiler.

How to use plugins/presets

Custom options can be passed in the 2nd argument of the function, allowing to configure your own plugins/presets:

// webpack.config.js
const useBabel = require('nullstack-adapt-babel')
const configs = require('nullstack/webpack.config')

module.exports = useBabel(configs, {
  babel: {
    plugins: [
      ['babel-plugin-transform-remove-console', { exclude: ['info'] }],
      '@babel/plugin-proposal-throw-expressions'
    ],
    presets: [['@babel/preset-flow', { allowDeclareFields: true }]]
  }
})

Currently custom plugins/presets are only appended to the original

Currently it have no option to customize our @babel/parser (e.g. with throwExpressions plugin)

Purpose

Someone may ask "Nullstack having a fast SWC compiler, why would one go back to the ~~future~~ past?", and understandable, like, I'm asking that myself even now finally documenting this all 😅

Not just fast, the beauty of that even got me seduced to learn some Rust and contribute at our own SWC plugin

Then yeah, there's some reasoning on bringing back the Babel days, aside from giving that plugins/presets freedom to the user and liking experiments, we wanted to use a platform like StackBlitz that currently doesn't support SWC binaries

Then this package makes possible projects like those:

Example projects