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

@moxy/next-compile-node-modules

v2.1.1

Published

Next.js plugin to compile all node_modules using Babel

Downloads

84

Readme

next-compile-node-modules

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

Next.js plugin to compile all node_modules using Babel.

Motivation

Package authors should publish any JavaScript code to npm as long as it's only pure valid JavaScript (any version). It doesn't make sense to compile at the package level because authors don't know in which context their packages will be used. For instance, a package that has been published with code compiled to ES5 may be used in app that only targets evergreen browsers, making the bundle unnecessarily larger (or vice-versa).

Instead, app developers should compile node_modules using babel-preset-env and instruct it to produce compatible for the browsers they want to support (e.g. "IE 11"). Popular boilerplate projects such as create-react-app now compile all node_modules and you should too!

This plugin changes Next.js's webpack config to compile all node_modules by default. While this has an impact on performance, it only slows down the first compilation and subsequent ones will be much faster thanks to the built-in cache.

Installation

$ npm i --save @moxy/next-compile-node-modules

Usage

// next.config.js
const withCompileNodeModules = require('@moxy/next-compile-node-modules');

module.exports = withCompileNodeModules({ ...options })({ ...nextConfig });

Multiple configurations can be combined together with function composition. For example:

// next.config.js
const withCSS = require('@zeit/next-css');
const withCompileNodeModules = require('@moxy/next-compile-node-modules');

module.exports = withCSS(
    withCompileNodeModules({
        exclude: [require.resolve('some-module')],
    })({
        cssModules: true, // this options will be passed to withCSS plugin through nextConfig
    }),
);

Available options

| Option | Description | Type | Default | | --- | --- | --- | --- | | test | The Webpack rule test condition | Rule.test | /\.js$/ | | include | The Webpack rule include condition | Rule.include | /[\\/]node_modules[\\/]/ | | exclude | Prepend exclusions to the Webpack rule exclude condition besides the built-in¹ ones | Rule.exclude | | | serverExternals | Prepend additional externals dependencies besides the built-in² ones. This option is ignored in the client build or when target is serverless | Any supported types

¹ Built-in exclusions are Next.js and Webpack related, such as node-libs-browser and process.

² Built-in externals are Next.js related as well as modules associated with React. More specifically, it prevents React from being bundled individually in each page which would cause issues such as "React Hooks would throw: Invalid Hook Call Warning".

Custom babel config

If you are using a custom babel.config.js, you may identify if we are compiling a node module or not via api.caller like so:

// babel.config.js

module.exports = (api) => {
    const isNodeModule = api.caller((caller) => caller.isNodeModule);

    // You may now use `isNodeModule` to conditionally make changes to the returned config

    return {
        // ...
    };
};

Tests

Any parameter passed to the test command, is passed down to Jest.

$ npm t
$ npm t -- --watch # during development

License

Released under the MIT License.