main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | /** @typedef {import("./Resolver")} Resolver */
|
---|
| 9 | /** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
|
---|
| 10 | /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
|
---|
| 11 |
|
---|
| 12 | module.exports = class UseFilePlugin {
|
---|
| 13 | /**
|
---|
| 14 | * @param {string | ResolveStepHook} source source
|
---|
| 15 | * @param {string} filename filename
|
---|
| 16 | * @param {string | ResolveStepHook} target target
|
---|
| 17 | */
|
---|
| 18 | constructor(source, filename, target) {
|
---|
| 19 | this.source = source;
|
---|
| 20 | this.filename = filename;
|
---|
| 21 | this.target = target;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * @param {Resolver} resolver the resolver
|
---|
| 26 | * @returns {void}
|
---|
| 27 | */
|
---|
| 28 | apply(resolver) {
|
---|
| 29 | const target = resolver.ensureHook(this.target);
|
---|
| 30 | resolver
|
---|
| 31 | .getHook(this.source)
|
---|
| 32 | .tapAsync("UseFilePlugin", (request, resolveContext, callback) => {
|
---|
| 33 | const filePath = resolver.join(
|
---|
| 34 | /** @type {string} */ (request.path),
|
---|
| 35 | this.filename
|
---|
| 36 | );
|
---|
| 37 |
|
---|
| 38 | /** @type {ResolveRequest} */
|
---|
| 39 | const obj = {
|
---|
| 40 | ...request,
|
---|
| 41 | path: filePath,
|
---|
| 42 | relativePath:
|
---|
| 43 | request.relativePath &&
|
---|
| 44 | resolver.join(request.relativePath, this.filename)
|
---|
| 45 | };
|
---|
| 46 | resolver.doResolve(
|
---|
| 47 | target,
|
---|
| 48 | obj,
|
---|
| 49 | "using path: " + filePath,
|
---|
| 50 | resolveContext,
|
---|
| 51 | callback
|
---|
| 52 | );
|
---|
| 53 | });
|
---|
| 54 | }
|
---|
| 55 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.