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.

29 lines
659 B

4 years ago
  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;