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

rollup-plugin-common-path-resolver

v1.0.1

Published

[English](README.md) | [中文](README_CN.md)

Downloads

2

Readme

rollup-plugin-common-path-resolver

English | 中文

rollup-plugin-common-path-resolver is a plugin designed for the Rollup bundling tool, aimed at improving the efficiency of resolving common paths in projects. Through custom configuration, this plugin can intelligently resolve and share code between different parts of a project, making it particularly suitable for large projects or multi-package repositories. Its main purpose is to support flexible code reuse in large projects or multi-package management scenarios (such as Monorepo structures), especially in scenarios where development is based on a standard product version. When it is necessary to import code or functionality modules from the standard version to build a specific product version, this plugin can offer great convenience and efficiency.

Scenario Example

Imagine you are maintaining a product with multiple versions, such as a standard version and several customized versions. Each version needs to reuse a large amount of code and components from the standard version while adding some specific functions or modifying certain features. Using rollup-plugin-common-path-resolver, you can easily share and reuse code between different parts of the project by simply configuring path resolution rules, without the need for complex relative path imports, making code management more concise and efficient.

Features

  • Automatic Path Resolution: Automatically resolves shared paths in the project, avoiding the complexity of manually specifying paths.
  • Highly Configurable: Provides a variety of configuration options to adapt to different project structures and needs.
  • Enhanced Code Shareability: Promotes the reuse of code within the project, simplifying the project structure.
  • Easy to Integrate: Can be easily integrated into the existing Rollup build process.

Installation

Using npm:

npm install rollup-plugin-common-path-resolver --save-dev

Using yarn:

yarn add rollup-plugin-common-path-resolver --dev

Using pnpm:

pnpm add rollup-plugin-common-path-resolver --dev

Usage

In the Rollup configuration file, import and configure rollup-plugin-common-path-resolver:

import commonPathResolver from 'rollup-plugin-common-path-resolver';

export default {
  // Other configurations...
  plugins: [
    commonPathResolver({
      // Configuration options
      packagePathSegment: 'packages',
      sourcePathSegment: 'src',
      commonFolderName: 'common',
      pathPrefix: '@',
    })
  ]
};

Configuration Options

  • packagePathSegment (string): The example path segment is used to locate packages within the project as well as the path to common packages. The default is 'packages'.
  • sourcePathSegment (string): The source code path segment, usually the directory where source code is stored in the project. Default is 'src'.
  • commonFolderName (string): The name of the common folder, used for directories sharing code. Default is 'common'.
  • pathPrefix (string): The path prefix, used to replace the source path prefix. Default is '@'.
  • exclude (RegExp): A regular expression to exclude specific paths, which will not be processed by the plugin.

Example

Suppose your project structure is as follows:

my-project/
  module1/
    src/
      index.js
  module2/
    src/
      index.js
  common/
    src/
      utils.js

You can use the rollup-plugin-common-path-resolver plugin, configuring the path prefix @ to point to the common directory, thus easily sharing the utils.js file between module1 and module2.

Further Exploration

To better understand how to use rollup-plugin-common-path-resolver, it is recommended to check out the project's packages directory. There, you will find more detailed sample code that can help you quickly get started and gain a deeper understanding of how to use this plugin.

Support and Contribution

If you encounter any problems or have suggestions for improvement, feel free to raise an issue or pull request in the project's GitHub repository.

License

This project is licensed under the MIT License. For detailed information, please see the LICENSE file.