123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- "use strict";
- const { OriginalSource, RawSource } = require("webpack-sources");
- const Module = require("./Module");
- const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
- const makeSerializable = require("./util/makeSerializable");
- const TYPES = new Set(["javascript"]);
- class RawModule extends Module {
-
- constructor(source, identifier, readableIdentifier, runtimeRequirements) {
- super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
- this.sourceStr = source;
- this.identifierStr = identifier || this.sourceStr;
- this.readableIdentifierStr = readableIdentifier || this.identifierStr;
- this.runtimeRequirements = runtimeRequirements || null;
- }
-
- getSourceTypes() {
- return TYPES;
- }
-
- identifier() {
- return this.identifierStr;
- }
-
- size(type) {
- return Math.max(1, this.sourceStr.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) {
- const sources = new Map();
- if (this.useSourceMap || this.useSimpleSourceMap) {
- sources.set(
- "javascript",
- new OriginalSource(this.sourceStr, this.identifier())
- );
- } else {
- sources.set("javascript", new RawSource(this.sourceStr));
- }
- return { sources, runtimeRequirements: this.runtimeRequirements };
- }
-
- updateHash(hash, context) {
- hash.update(this.sourceStr);
- super.updateHash(hash, context);
- }
-
- serialize(context) {
- const { write } = context;
- write(this.sourceStr);
- write(this.identifierStr);
- write(this.readableIdentifierStr);
- write(this.runtimeRequirements);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.sourceStr = read();
- this.identifierStr = read();
- this.readableIdentifierStr = read();
- this.runtimeRequirements = read();
- super.deserialize(context);
- }
- }
- makeSerializable(RawModule, "webpack/lib/RawModule");
- module.exports = RawModule;
|