You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RawModule.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Module = require("./Module");
  7. const { OriginalSource, RawSource } = require("webpack-sources");
  8. module.exports = class RawModule extends Module {
  9. constructor(source, identifier, readableIdentifier) {
  10. super("javascript/dynamic", null);
  11. this.sourceStr = source;
  12. this.identifierStr = identifier || this.sourceStr;
  13. this.readableIdentifierStr = readableIdentifier || this.identifierStr;
  14. this.built = false;
  15. }
  16. identifier() {
  17. return this.identifierStr;
  18. }
  19. size() {
  20. return this.sourceStr.length;
  21. }
  22. readableIdentifier(requestShortener) {
  23. return requestShortener.shorten(this.readableIdentifierStr);
  24. }
  25. needRebuild() {
  26. return false;
  27. }
  28. build(options, compilations, resolver, fs, callback) {
  29. this.built = true;
  30. this.buildMeta = {};
  31. this.buildInfo = {
  32. cacheable: true
  33. };
  34. callback();
  35. }
  36. source() {
  37. if (this.useSourceMap) {
  38. return new OriginalSource(this.sourceStr, this.identifier());
  39. } else {
  40. return new RawSource(this.sourceStr);
  41. }
  42. }
  43. updateHash(hash) {
  44. hash.update(this.sourceStr);
  45. super.updateHash(hash);
  46. }
  47. };