ExportPropertyMainTemplatePlugin.js 833B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ConcatSource = require("webpack-sources").ConcatSource;
  7. function accessorToObjectAccess(accessor) {
  8. return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
  9. }
  10. class ExportPropertyMainTemplatePlugin {
  11. constructor(property) {
  12. this.property = property;
  13. }
  14. apply(compilation) {
  15. const mainTemplate = compilation.mainTemplate;
  16. compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => {
  17. const postfix = `${accessorToObjectAccess([].concat(this.property))}`;
  18. return new ConcatSource(source, postfix);
  19. });
  20. mainTemplate.plugin("hash", hash => {
  21. hash.update("export property");
  22. hash.update(`${this.property}`);
  23. });
  24. }
  25. }
  26. module.exports = ExportPropertyMainTemplatePlugin;