1. class MyPlugin {
    2. constructor (options) {
    3. this.userOptions = options || { }
    4. }
    5. apply(compiler) {
    6. compiler.hooks.emit.tap('cleanTest', (compilation) => {
    7. for (const name in compilation.assets) {
    8. if (name.endsWith(this.userOptions.target)) {
    9. const contents = compilation.assets[name].source()
    10. const noComments = contents.replace(/\/\*[\s\S]*?\*\//g, '')
    11. compilation.assets[name] = {
    12. source: () => noComments,
    13. size: () => noComments.length
    14. }
    15. }
    16. }
    17. })
    18. }
    19. }
    20. module.exports = MyPlugin