1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { URL, fileURLToPath } = require("url");
|
9 |
|
10 |
|
11 |
|
12 | class FileUriPlugin {
|
13 | |
14 |
|
15 |
|
16 |
|
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;
|