thgh

payload plugin resolve alias

by thgh
Testing & developer experience
v1
^1
MIT

Overview

Summary generated from the README

A Payload 1.x plugin that adds webpack resolve aliases to the admin build through a single helper function. It fixes module-not-found errors caused by Node.js core or server-only modules being pulled into the browser bundle. It ships a built-in list of common server-only modules and accepts objects, arrays or strings.

Features

  • Helper function that registers webpack aliases from the plugins array
  • Built-in list of common server-only modules such as express, nodemailer, passport and util
  • Accepts objects, arrays or strings as arguments
  • Ignores falsy arguments so aliases can be added conditionally by environment

Use cases

  • Fix webpack errors about missing Node.js core modules like util in the Payload admin build
  • Exclude server-only packages such as nodemailer from the browser bundle

From the author

Shorthand to add common webpack aliases

Installation

npm i payload-plugin-resolve-alias

7

Stars

1

Forks

0

Open Issues

2 years ago

Last Updated

1.2k

Weekly Downloads

v0.1.0

npm Version

7.4 KB

Unpacked Size

0

Dependencies

GitHub stars

70 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20267
Dec 5, 20267
Dec 4, 20267
Dec 3, 20267
Dec 2, 20267
Dec 1, 20267
Nov 30, 20267
Nov 29, 20267
Nov 28, 20267
Nov 27, 20267
Nov 26, 20267
Nov 25, 20267
Nov 24, 20267
Nov 23, 20267
Nov 22, 20267
Nov 21, 20267
Nov 20, 20267
Nov 19, 20267
Nov 18, 20267
Nov 17, 20267
Nov 16, 20267
Nov 15, 20267
Nov 14, 20267
Nov 13, 20267
Nov 12, 20267
Nov 11, 20267
Nov 10, 20267
Nov 9, 20267
Nov 8, 20267
Nov 7, 20267
Nov 6, 20267
Nov 5, 20267
Nov 4, 20267
Nov 3, 20267
Nov 2, 20267
Nov 1, 20267
Oct 31, 20267
Oct 30, 20267
Oct 29, 20267
Oct 28, 20267
Oct 27, 20267
Oct 26, 20267
Oct 25, 20267
Oct 24, 20267
Oct 23, 20267
Oct 22, 20267
Oct 21, 20267
Oct 20, 20267
Oct 19, 20267
Oct 18, 20267
Oct 17, 20267
Oct 16, 20267
Oct 15, 20267
Oct 14, 20267
Oct 13, 20267
Oct 12, 20267
Oct 11, 20267
Oct 10, 20267
Oct 9, 20267
Oct 8, 20267
Oct 7, 20267
Oct 6, 20267
Oct 5, 20267
Oct 4, 20267
Oct 3, 20267
Oct 2, 20267
Oct 1, 20267
Sep 30, 20267
Sep 29, 20267
Sep 28, 20267
Sep 27, 20267
Sep 26, 20267
Sep 25, 20267
Sep 24, 20267
Sep 23, 20267
Sep 22, 20267
Sep 21, 20267
Sep 20, 20267
Sep 19, 20267
Sep 18, 20267
Sep 17, 20267
Sep 16, 20267
Sep 15, 20267
Sep 14, 20267
Sep 13, 20267
Sep 12, 20267
Sep 11, 20267
Sep 10, 20267
Sep 9, 20267
Sep 8, 20267
Sep 7, 20267
npm weekly downloads

1.2K+195 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 20261,222
Dec 5, 20261,134
Dec 4, 2026933
Dec 3, 2026937
Dec 2, 20261,036
Dec 1, 20261,039
Nov 30, 20261,026
Nov 29, 20261,118
Nov 28, 20261,148
Nov 27, 20261,399
Nov 26, 20261,506
Nov 25, 20261,450
Nov 24, 20261,532
Nov 23, 20261,563
Nov 22, 20261,409
Nov 21, 20261,468
Nov 20, 20261,174
Nov 19, 2026970
Nov 18, 2026750
Nov 17, 2026711
Nov 16, 2026735
Nov 15, 2026664
Nov 14, 2026524
Nov 13, 2026498
Nov 12, 2026544
Nov 11, 2026609
Nov 10, 2026599
Nov 9, 2026555
Nov 8, 2026501
Nov 7, 2026408
Nov 6, 2026387
Nov 5, 2026356
Nov 4, 2026339
Nov 3, 2026344
Nov 2, 2026334
Nov 1, 2026406
Oct 31, 2026417
Oct 30, 2026414
Oct 29, 2026292
Oct 28, 2026226
Oct 27, 2026183
Oct 26, 2026319
Oct 25, 2026232
Oct 24, 2026210
Oct 23, 2026169
Oct 22, 2026196
Oct 21, 2026205
Oct 20, 2026211
Oct 19, 202682
Oct 18, 202672
Oct 17, 2026107
Oct 16, 2026187
Oct 15, 2026197
Oct 14, 2026223
Oct 13, 2026221
Oct 12, 2026211
Oct 11, 2026213
Oct 10, 2026364
Oct 9, 2026538
Oct 8, 2026793
Oct 7, 2026927
Oct 6, 2026975
Oct 5, 20261,074
Oct 4, 20261,402
Oct 3, 20261,466
Oct 2, 20261,498
Oct 1, 20261,367
Sep 30, 20261,368
Sep 29, 20261,327
Sep 28, 20261,243
Sep 27, 20261,077
Sep 26, 20261,022
Sep 25, 20261,008
Sep 24, 20261,076
Sep 23, 2026939
Sep 22, 2026937
Sep 21, 2026921
Sep 20, 2026822
Sep 19, 2026637
Sep 18, 2026385
Sep 17, 2026209
Sep 16, 2026232
Sep 15, 2026226
Sep 14, 2026231
Sep 13, 2026201
Sep 12, 2026233
Sep 11, 2026350
Sep 10, 2026564
Sep 9, 2026707
Sep 8, 2026857
Sep 7, 20261,027

Each point is npm's rolling 7-day download count.

Health Score

49/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/562124033-root.svg)](https://payloaddirectory.dev/plugins/562124033-root)
HTML
<a href="https://payloaddirectory.dev/plugins/562124033-root"><img src="https://payloaddirectory.dev/badge/562124033-root.svg" alt="Payload Directory"></a>
Updated Dec 10, 2023Created Nov 5, 2022Published Nov 5, 2022

README

Resolve alias webpack helper for Payload CMS

Software License Issues NPM

Encountered this?

ERROR in ./node_modules/next/dist/compiled/micromatch/index.js 22:3471-3486
Module not found: Error: Can't resolve 'util' in '\node_modules\next\dist\compiled\micromatch'

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: { "util": require.resolve("util/") }'
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "util": false }

Features

  • Easy way to fix the webpack error
  • Built-in list of common server-only modules

Installation

npm install payload-plugin-resolve-alias
# or
yarn add payload-plugin-resolve-alias

Usage

// payload.config.ts
import { resolveAlias, serverOnlyModules } from 'payload-plugin-resolve-alias'

export default buildConfig({
  plugins: [
    resolveAlias(serverOnlyModules, ['nodemailer']),

    // Alternative syntax
    resolveAlias(
      // Object
      { nodemailer: false, passport: false },
      // Arra
      ['nodemailer', 'passport'],
      // String
      'nodemailer',
      'passport',
      // Falsy arguments are ignored
      process.env.NODE_ENV === 'production' && ['production-only']
    ),
  ],
})

Community-driven list of server-only modules

serverOnlyModules is an array of modules that you probably don't want in the browser:

  • express
  • express-session
  • nodemailer
  • passport
  • util

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Contributions and feedback are very welcome.

To get it running:

  1. Clone the project.
  2. npm install
  3. npm run build

Credits

License

The MIT License (MIT). Please see License File for more information.

Similar plugins