NamedChunksPlugin.js 659 B

1234567891011121314151617181920212223242526272829
  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.hooks.compilation.tap("NamedChunksPlugin", compilation => {
  15. compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", chunks => {
  16. for (const chunk of chunks) {
  17. if (chunk.id === null) {
  18. chunk.id = this.nameResolver(chunk);
  19. }
  20. }
  21. });
  22. });
  23. }
  24. }
  25. module.exports = NamedChunksPlugin;