namedModulesPlugin.js 681 B

123456789101112131415161718192021222324252627282930
  1. const {
  2. addOrUpdateConfigObject,
  3. findAndRemovePluginByName
  4. } = require("../../utils/ast-utils");
  5. /**
  6. *
  7. * Transform for NamedModulesPlugin. If found, removes the
  8. * plugin and sets optimizations.namedModules to true
  9. *
  10. * @param {Object} j - jscodeshift top-level import
  11. * @param {Node} ast - jscodeshift ast to transform
  12. * @returns {Node} ast - jscodeshift ast
  13. */
  14. module.exports = function(j, ast) {
  15. // Remove old plugin
  16. const root = findAndRemovePluginByName(j, ast, "webpack.NamedModulesPlugin");
  17. // Add new optimizations option
  18. root &&
  19. addOrUpdateConfigObject(
  20. j,
  21. root,
  22. "optimizations",
  23. "namedModules",
  24. j.booleanLiteral(true)
  25. );
  26. return ast;
  27. };