NamedChunksPlugin.js 623B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class NamedChunksPlugin {
  7. static defaultNameResolver(chunk) {
  8. return chunk.name || null;
  9. }
  10. constructor(nameResolver) {
  11. this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver;
  12. }
  13. apply(compiler) {
  14. compiler.plugin("compilation", (compilation) => {
  15. compilation.plugin("before-chunk-ids", (chunks) => {
  16. chunks.forEach((chunk) => {
  17. if(chunk.id === null) {
  18. chunk.id = this.nameResolver(chunk);
  19. }
  20. });
  21. });
  22. });
  23. }
  24. }
  25. module.exports = NamedChunksPlugin;