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

webpack-theme-resolver-plugin

v4.0.0

Published

Webpack Theme Resolver plugin to resolve files through directory chain with a package fallback at compile time.

Downloads

264

Readme

webpack-theme-resolver-plugin

Webpack Theme Resolver plugin to resolve files through a directory chain with a package fallback at compile time. For Webpack 4+

Based on the fallback-directory-resolver-plugin from kije

Description

This is a Resolver-Plugin for webpack. It enables resolving files by looking up multiple directories in a chain with an fallback package.

This is especially useful when you need to change a single component nested inside another component or other nested components.

For example you have a library of components with a SimpleList containing a ListEntry which you'd like to change. Without webpack-theme-resolver-plugin you'd need to create your ow implementation of SimpleList in order to be able to inject a different ListEntry. With this plugin you can simply create a ListEntry component which will then be used instead of the original one as long its path is the same and both components are imported using the same configurable prefix (see below).

Here an Example with vue and 2 local themes (it works with any file ending):

/sample-app
  - /components
    - /default-theme
      - /List
        - SimpleList.vue (js or other)
        - ListEntry.vue
    - /fancy-theme
      - /List
        - ListEntry.vue

Installation

Install this plugin via npm alongside with webpack.

# for npm
npm install --save-dev webpack-theme-resolver-plugin

# or for yarn
yarn add -D webpack-theme-resolver-plugin

Config

// webpack.config.js

const path = require('path');
const ThemeResolverPlugin = require('webpack-theme-resolver-plugin')

module.exports = {
    ...
    resolve: {
        plugins: [
            new ThemeResolverPlugin(
                [
                    {
                        prefix: 'theme-components',
                        directories: [
                            path.resolve(__dirname, 'components/fancy-theme'),
                            path.resolve(__dirname, 'components/default-theme'),
                        ],
                        module: 'awesome-components',
                        singlePackage: true
                    }
                ]
            )
        ]
    }
};

| Option | Required | Default | Description | | ------------- |:-------- |:------- | ------------ | | prefix | yes | | Prefix for the import to trigger resolve | | directories | yes | | The Directories to look through | | module | no | | The Fallback Component to search for the component | | singlePackage | no | true | Are all components in one package or one package per component | | modulePath | no | /src | The Path in the Module to look up |

The directories will be scanned in the order provided, falling back to module if no matching file is found.

In order to trigger the plugin the import statements need to be changed to include the set up prefix

// will resolve to SimpleList.vue in components/default-theme/List/SimpleList.vue
import SimpleList from 'theme-components/components/List/SimpleList.vue'

// will resolve to ListEntry.vue in components/fancy-theme/List/ListEntry.vue
import ListEntry from 'theme-components/components/List/ListEntry.vue'

This way you can specify different configurations by having different prefix and directories set up.

Example

Check out our Example made with Vue here webpack-theme-resolver-plugin-example.

Tests

To run the tests in this package follow this steps

  1. Install plugin packages
npm i
  1. Build the plugin
npm run build
  1. Switch to the test-app
cd example/test-app
  1. Install the test packages
npm i
  1. Run the Test
npm run test
  1. Results should be
Hello from Dir 1
Test from Dir 2
Goodbye from Dir 3
Hello from external package