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

file-override-webpack-plugin

v0.0.1

Published

A Webpack plugin that enables overriding files/imports from a source folder with matching files from another folder.

Downloads

4

Readme

File Override Webpack Plugin

FileOverridePlugin is a Webpack plugin that allows you to override any files that are imported from a particular folder with files from another folder of your choosing. Simply place a file with the same name in your chosen override directory.

For example, let's say you're a web dev freelancer/agency with a monorepo that contains multiple websites for each of your clients, and you extract a bunch of commonly used React components into a standalone UI kit package for reusability. In this shared UI kit, you have a primitive Button component. If you wanted to customize/override this Button for a particular client project, you could import it and create your own "wrapper" component which applies some custom styling etc.. BUT, the Button from the UI kit is also imported into other larger components in your UI kit, such as a CallToAction component -- how do you ensure that CallToAction uses your project-specific Button instead of the shared Button? The short answer is: use this plugin.

Extending the above example, FileOverridePlugin allows you to say "when importing anything from ./ui-kit/**, first check if there's a matching file in ./project-x/**, and if so we import from that file instead (if not, import as usual). It works with nested files too (eg. to override ./ui-kit/primitives/button.tsx, create a file at ./project-x/primitives/button.tsx).

Installation

npm install --save-dev file-override-webpack-plugin

Usage

To use the FileOverridePlugin, add it to your Webpack configuration file (webpack.config.js or similar):

import FileOverridePlugin from "file-override-webpack-plugin";

const webpackConfig = {
  // Other Webpack configurations...
  resolve: {
    plugins: [
      new FileOverridePlugin({
        sourcePath: "node_modules/ui-kit/src/components",
        overridePath: "./src/components",
        fileExtensions: ["tsx", "ts", "js", "jsx"],
        log: true,
      }),
    ],
  },
};

Next.js Example

const nextConfig = {
  // Other Next.js configurations...
  webpack: (config, context) => {
    config.resolve.plugins.push(
      new FileOverridePlugin({
        sourcePath: "node_modules/ui-kit/src/components",
        overridePath: "./src/components",
      })
    );

    return config;
  },
};

Configuration Options

| Option | Type | Description | Default | | ---------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | | sourcePath | string | This actually isn't a relative or absolute path, it's any unique portion of the path to your source folder to match against. Example: "node_modules/ui-kit/src/components". | Required | | overridePath | string | The path to your override folder or directory, relative to your Webpack configuration. Example: "./src/components". | Required | | fileExtensions | string[] | Array of file extensions to check for when resolving file paths. The plugin will look for files with these extensions in the override directory. | ['tsx', 'ts', 'js', 'jsx'] | | log | boolean | Enable or disable logging to the console to see which files are being overridden during the build. | false |

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.