webpack/lib/RawModule.js

97 lines
2.6 KiB
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const Module = require("./Module");
const { OriginalSource, RawSource } = require("webpack-sources");
/** @typedef {import("./util/createHash").Hash} Hash */
/** @typedef {import("./Compilation")} Compilation */
/** @typedef {import("./RequestShortener")} RequestShortener */
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("webpack-sources").Source} Source */
module.exports = class RawModule extends Module {
constructor(source, identifier, readableIdentifier) {
2018-01-31 04:40:44 +08:00
super("javascript/dynamic", null);
this.sourceStr = source;
this.identifierStr = identifier || this.sourceStr;
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
this.built = false;
}
/**
* @returns {string} a unique identifier of the module
*/
identifier() {
return this.identifierStr;
}
/**
* @returns {number} the estimated size of the module
*/
size() {
return this.sourceStr.length;
}
/**
* @param {RequestShortener} requestShortener the request shortener
* @returns {string} a user readable identifier of the module
*/
readableIdentifier(requestShortener) {
return requestShortener.shorten(this.readableIdentifierStr);
}
2018-07-25 18:38:34 +08:00
/**
* @param {TODO} fileTimestamps timestamps of files
* @param {TODO} contextTimestamps timestamps of directories
* @returns {boolean} true, if the module needs a rebuild
*/
needRebuild(fileTimestamps, contextTimestamps) {
return false;
}
/**
* @param {TODO} options TODO
* @param {Compilation} compilation the compilation
* @param {TODO} resolver TODO
* @param {TODO} fs the file system
* @param {function(Error=): void} callback callback function
* @returns {void}
*/
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.buildMeta = {};
this.buildInfo = {
cacheable: true
};
callback();
}
/**
* @param {DependencyTemplates} dependencyTemplates the dependency templates
* @param {RuntimeTemplate} runtimeTemplate the runtime template
* @param {string=} type the type of source that should be returned
* @returns {Source} generated source
*/
source(dependencyTemplates, runtimeTemplate, type) {
if (this.useSourceMap) {
return new OriginalSource(this.sourceStr, this.identifier());
} else {
return new RawSource(this.sourceStr);
}
}
/**
* @param {Hash} hash the hash used to track dependencies
* @returns {void}
*/
updateHash(hash) {
hash.update(this.sourceStr);
super.updateHash(hash);
}
2017-01-11 17:51:58 +08:00
};