Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
961 bytes
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const { URL, fileURLToPath } = require("url");
|
---|
9 |
|
---|
10 | /** @typedef {import("../Compiler")} Compiler */
|
---|
11 |
|
---|
12 | class FileUriPlugin {
|
---|
13 | /**
|
---|
14 | * Apply the plugin
|
---|
15 | * @param {Compiler} compiler the compiler instance
|
---|
16 | * @returns {void}
|
---|
17 | */
|
---|
18 | apply(compiler) {
|
---|
19 | compiler.hooks.compilation.tap(
|
---|
20 | "FileUriPlugin",
|
---|
21 | (compilation, { normalModuleFactory }) => {
|
---|
22 | normalModuleFactory.hooks.resolveForScheme
|
---|
23 | .for("file")
|
---|
24 | .tap("FileUriPlugin", resourceData => {
|
---|
25 | const url = new URL(resourceData.resource);
|
---|
26 | const path = fileURLToPath(url);
|
---|
27 | const query = url.search;
|
---|
28 | const fragment = url.hash;
|
---|
29 | resourceData.path = path;
|
---|
30 | resourceData.query = query;
|
---|
31 | resourceData.fragment = fragment;
|
---|
32 | resourceData.resource = path + query + fragment;
|
---|
33 | return true;
|
---|
34 | });
|
---|
35 | }
|
---|
36 | );
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | module.exports = FileUriPlugin;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.