Change source code of a module via AST from a WebPack 4 plugin
问题 I have the following JS file: // hello-foo.js console.log('foo') I want to replace 'foo' with 'bar' with webpack. I have the following WebPack plugin for that: class MyPlugin { constructor() {} apply(compiler) { compiler .hooks .compilation .tap('MyPlugin', (compilation, {normalModuleFactory}) => { normalModuleFactory .hooks .parser .for('javascript/auto') .tap('MyPlugin', (parser) => { parser .hooks .program .tap('MyPlugin', (ast, comments) => { ast.body[0].expression.arguments[0].value =