JSPM

webpack-theme-resolver-plugin

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 669
  • Score
    100M100P100Q131888F
  • License MIT

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

Package Exports

  • webpack-theme-resolver-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (webpack-theme-resolver-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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. So for example you got a default-theme list component which got a ListEntry Component and you only want to overwrite the ListEntry Component in a new theme. Or the list component is part of an own component library, you can easily overwrite his child components from the local project.

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.

npm install --save-dev 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

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