123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- "use strict";
- const { RawSource } = require("webpack-sources");
- const Module = require("../Module");
- const { ASSET_MODULE_TYPE_RAW_DATA_URL } = require("../ModuleTypeConstants");
- const RuntimeGlobals = require("../RuntimeGlobals");
- const makeSerializable = require("../util/makeSerializable");
- const TYPES = new Set(["javascript"]);
- class RawDataUrlModule extends Module {
-
- constructor(url, identifier, readableIdentifier) {
- super(ASSET_MODULE_TYPE_RAW_DATA_URL, null);
- this.url = url;
- this.urlBuffer = url ? Buffer.from(url) : undefined;
- this.identifierStr = identifier || this.url;
- this.readableIdentifierStr = readableIdentifier || this.identifierStr;
- }
-
- getSourceTypes() {
- return TYPES;
- }
-
- identifier() {
- return this.identifierStr;
- }
-
- size(type) {
- if (this.url === undefined)
- this.url = (this.urlBuffer).toString();
- return Math.max(1, this.url.length);
- }
-
- readableIdentifier(requestShortener) {
- return (
- requestShortener.shorten(this.readableIdentifierStr)
- );
- }
-
- needBuild(context, callback) {
- return callback(null, !this.buildMeta);
- }
-
- build(options, compilation, resolver, fs, callback) {
- this.buildMeta = {};
- this.buildInfo = {
- cacheable: true
- };
- callback();
- }
-
- codeGeneration(context) {
- if (this.url === undefined)
- this.url = (this.urlBuffer).toString();
- const sources = new Map();
- sources.set(
- "javascript",
- new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
- );
- const data = new Map();
- data.set("url", this.urlBuffer);
- const runtimeRequirements = new Set();
- runtimeRequirements.add(RuntimeGlobals.module);
- return { sources, runtimeRequirements, data };
- }
-
- updateHash(hash, context) {
- hash.update( (this.urlBuffer));
- super.updateHash(hash, context);
- }
-
- serialize(context) {
- const { write } = context;
- write(this.urlBuffer);
- write(this.identifierStr);
- write(this.readableIdentifierStr);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.urlBuffer = read();
- this.identifierStr = read();
- this.readableIdentifierStr = read();
- super.deserialize(context);
- }
- }
- makeSerializable(RawDataUrlModule, "webpack/lib/asset/RawDataUrlModule");
- module.exports = RawDataUrlModule;
|