Issue 1:
I'm submitting a feature request

Webpack version:

2.1

Expected/desired behavior:

Currently it's possible to either load modules by their ID's (e.g. __webpack_require__(123) or create a custom context (require.context(...)) which maps paths to module IDs.

It would be great to have a way to create arbitrary "contexts" of modules which were previously in the bundle. What I mean by that is creating a simple mapping to resolve arbitrary names (set by the plugin) to actual module IDs, without adding any extra ones.

I've managed to hack together something based on the ContextReplacementPlugin, but it's not a good solution, because the modules need to be added manually, plus it duplicates the modules instead of referencing the ones which are already there. I want to add new modules, just be able to access them using an "alternative module ID", stored in the context map.

I'd be happy to implement this myself, as a plugin, but I'm not sure what's the best way - the ContextModuleFactory is quite complex. It seems to me, I'd need to duplicate that and just make it much simpler -- unless there's a better way?

What is the motivation / use case for changing the behavior?

Some applications need to use arbitrary, dynamically generated names for importing modules. This would enable such use cases, given that the names are predictable (e.g. file-paths).

const ctxRequire = require.customContext('my-context-name');
const someModule = ctxRequire('my-custom-reference');
const someOtherModule = ctxRequire(dynamicallyGeneratedName);

In other words it's like alternative module IDs. I could just hook 'before-module-ids' and change the module.id of each module and then use __webpack_require__ directly, but that way I'm limiting ourselves to a single set of custom references, while it might make sense to keep multiple aliases for the same module, e.g. with and without the extension, similarly to how the ContextReplacementPlugin works:

Given the following Context Map:

{
"my-custom-reference": 123,
"my-custom-reference.js": 123
}

Usage:

const ctxRequire = require.customContext('my-context-name');
const someModule = ctxRequire('my-custom-reference'); // without extension
const sameModule = ctxRequire('my-custom-reference.js'); // with extension

For adding names I'd imagine the consumer of such plugin could either:

create a simple loader that doesn't modify the source, but adds the array of aliases for a given context

use a Compilation plugin hook like 'normal-module-loader' to create and add the array of aliases given each module

Issue 2:
Bug report

What is the current behavior?

when i use quill@1.x, it work. but 2.0 is not work. it report error is _webpack_require is not defined

If the current behavior is a bug, please provide the steps to reproduce.

compare the version of quill. webpack5 seems not support module:"es6"

the quill@1.x config is

{ test: /\.ts$/, use: [{ loader: 'ts-loader', options: { compilerOptions: { declaration: false, target: 'es5', module: 'commonjs' }, transpileOnly: true } }] }

the quill@2 config

test: /\.ts$/, use: [ { loader: 'ts-loader', options: { compilerOptions: { declaration: false, module: 'es6', sourceMap: true, target: 'es6', }, transpileOnly: true, }, }, ],

What is the expected behavior?

it can work well

Other relevant information:

webpack version:

Node.js version:

Operating System:

Additional tools: