Projekt

Obecné

Profil

Stáhnout (1.17 KB) Statistiky
| Větev: | Revize:
1
/*
2
	MIT License http://www.opensource.org/licenses/mit-license.php
3
	Author Tobias Koppers @sokra
4
*/
5
"use strict";
6

    
7
module.exports = class ModuleAppendPlugin {
8
	constructor(source, appending, target) {
9
		this.source = source;
10
		this.appending = appending;
11
		this.target = target;
12
	}
13

    
14
	apply(resolver) {
15
		const target = resolver.ensureHook(this.target);
16
		resolver.getHook(this.source).tapAsync("ModuleAppendPlugin", (request, resolveContext, callback) => {
17
			const i = request.request.indexOf("/"),
18
				j = request.request.indexOf("\\");
19
			const p = i < 0 ? j : j < 0 ? i : i < j ? i : j;
20
			let moduleName, remainingRequest;
21
			if(p < 0) {
22
				moduleName = request.request;
23
				remainingRequest = "";
24
			} else {
25
				moduleName = request.request.substr(0, p);
26
				remainingRequest = request.request.substr(p);
27
			}
28
			if(moduleName === "." || moduleName === "..")
29
				return callback();
30
			const moduleFinalName = moduleName + this.appending;
31
			const obj = Object.assign({}, request, {
32
				request: moduleFinalName + remainingRequest
33
			});
34
			resolver.doResolve(target, obj, "module variation " + moduleFinalName, resolveContext, callback);
35
		});
36
	}
37
};
(17-17/39)