镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

About

Get aliases for your workspace packages for Jest, Webpack and Rollup

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

workspace-alias

Forked from lerna-alias.

Simple package for getting alias object for packages managed by npm or yarn workspaces, so other tools (such as webpack, rollup, jest and possibly more) can consume your packages directly from the source files, instead of the built and prepared distribution files.

It just eases development and setting up scripts depending on other monorepo packages.

API

workspaceAliases({
  // from which directory monorepo should be searched for
  directory: string = process.cwd(),
  // optional array of `mainFields` that should be used to resolv package's entry point
  // similar to the https://webpack.js.org/configuration/resolve/#resolve-mainfields
  // using this takes precedence over default `sourceDirectory` option
  mainFields?: string[],
  // which directory should be considered as containing source files of a package
  // if specified as false it will use package's root and rely on a tool's (i.e. webpack) resolving algorithm
  sourceDirectory: string | false = 'src'
}): Aliases

Types

Aliases

type Aliases = {
  // value is a local directory path to the package
  // resolved using `sourceDirectory` and `mainFields` options
  [packageName: string]: string,
}

Usage

with webpack

const { webpack: workspaceAliases } = require('workspace-alias')

module.exports = {
  // ...
  resolve: {
    // ...
    alias: workspaceAliases(),
  },
}

with Rollup

const { rollup: workspaceAliases } = require('workspace-alias')
const workspaceAliases = require('workspace-alias')

module.exports = {
  // ...
  plugins: [
    // ...
    alias(workspaceAliases()),
  ],
}

with Jest

const { jest: workspaceAliases } = require('workspace-alias')

module.exports = {
  // ...
  moduleNameMapper: workspaceAliases(),
}

using mainFields option

const { jest: workspaceAliases } = require('workspace-alias')

module.exports = {
  // ...
  moduleNameMapper: workspaceAliases({ mainFields: ['main'] }),
}

About

Get aliases for your workspace packages for Jest, Webpack and Rollup

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages