webpack自定义插件
感受下webpack的插件能力,在打包后创建一个json文件
const fs = require("fs");
const PLUGIN_NAME = 'CreateJsonPlugin'
class CreateJsonPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tapAsync(PLUGIN_NAME, async (compilation, cb) => {
const logger = compilation.getLogger(PLUGIN_NAME)
// const logger = compiler.getInfrastructureLogger(PLUGIN_NAME)
logger.info('create version.jon')
const path = './dist/version.json'
const content = `123456789`
await fs.writeFileSync(path, content)
cb()
})
}
}
module.exports = CreateJsonPlugin