1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const NormalModule = require("../NormalModule");
|
9 | const { getMimetype, decodeDataURI } = require("../util/DataURI");
|
10 |
|
11 |
|
12 |
|
13 | class DataUriPlugin {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | apply(compiler) {
|
20 | compiler.hooks.compilation.tap(
|
21 | "DataUriPlugin",
|
22 | (compilation, { normalModuleFactory }) => {
|
23 | normalModuleFactory.hooks.resolveForScheme
|
24 | .for("data")
|
25 | .tap("DataUriPlugin", resourceData => {
|
26 | resourceData.data.mimetype = getMimetype(resourceData.resource);
|
27 | });
|
28 | NormalModule.getCompilationHooks(compilation)
|
29 | .readResourceForScheme.for("data")
|
30 | .tap("DataUriPlugin", resource => decodeDataURI(resource));
|
31 | }
|
32 | );
|
33 | }
|
34 | }
|
35 |
|
36 | module.exports = DataUriPlugin;
|