webpack-contrib / expose-loader

Expose Loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docs Mismatch and Absolutely no "local" Examples

SampsonCrowley opened this issue · comments

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?

Please Explain in Detail...

  1. Docs Mismatch: https://github.com/webpack-contrib/expose-loader#options

The exposes String documentation doesn't stick to one library:

First it shows a snippet of the underscore library

import _ from "underscore";

Then it shows an example config for jQuery, that contains comments about underscore (notice the comment right above the exposes key

module.exports = {
  module: {
    rules: [
      {
        test: require.resolve("jquery"),
        loader: "expose-loader",
        options: {
          // For `underscore` library, it can be `_.map map` or `_.map|map`
          exposes: "jquery",
        },
      },
    ],
  },
};
  1. No "Local" examples

There is not a single example in the docs of exposing a "Local" module. This is my particular need, and I'm in the boat of needing to just trial and error whether this is a feature that is even supported. (is it? I assume it is, but it's not mentioned once,only libraries from node_modules, and the require.resolve requirement with no option to use regex or any other form of standard testing that other loaders allow doesn't make the non-node_modules exposing less confusing for newcomers)

Your Proposal for Changes

Fix the mismatched docs to contain the right module for the example

Provide at least 1 "Sample" config of exposing a custom module that is not a pre-built node_modules module

Allow testing by Regex, it is up to the end-user to properly vet that their test is scoped to a single module; shouldn't need to force using built-in node require.resolve. This will also ease development burden in situations where users know they can use other methods that don't require an exact path and don't need to break a bundle if they restructure their files slightly

PR welcome