Webpack plugin to modify files after compilation

前端 未结 1 675
死守一世寂寞
死守一世寂寞 2021-01-18 15:40

I am writing a Webpack plugin that should replace a part of the JS code with a list of Webpack\'s generated CSS files. Imaging this JS code:

ReactWebComponen         


        
1条回答
  •  既然无缘
    2021-01-18 16:21

    It appears this sort of thing is simple enough to be handled by loaders, of which there are multiple (some better than others):

    https://www.npmjs.com/package/string-replace-loader

    https://www.npmjs.com/package/regexp-replace-loader

    https://www.npmjs.com/package/replace-loader

    If you want to go about making your own plugin to do this (I just went through the process to do something a bit more sophisticated than just regex replacement), I was able to piece my solution together from basically these three pages:

    https://github.com/webpack/webpack/blob/master/lib/BannerPlugin.js

    https://webpack.js.org/api/plugins/compilation/#optimize-chunk-assets-chunks-chunk-async

    https://github.com/webpack/webpack-sources

    0 讨论(0)
提交回复
热议问题