blessing-skin-server/tools/SyncMetaJsPlugin.ts
Pig Fang 34c90b50f2
upgrade to webpack 5
Web CLI update:
* commander -> cac
* enquirer -> prompts
2020-11-06 15:37:45 +08:00

25 lines
608 B
TypeScript

import { promises as fs } from 'fs'
import * as path from 'path'
import type { Compiler } from 'webpack'
class SyncMetaJsPlugin {
apply(compiler: Compiler) {
compiler.hooks.assetEmitted.tapPromise(
'HtmlWebpackEnhancementPlugin',
async (name, { source }) => {
if (compiler.options.mode !== 'development') {
return
}
if (name === 'meta.js' || name === 'sw.js') {
const filePath = path.resolve(process.cwd(), 'public', name)
await fs.writeFile(filePath, source.source())
}
},
)
}
}
export default SyncMetaJsPlugin