MCPcopy Create free account
hub / github.com/thx/gogocode / apply

Method apply

example/demo-with-webpack-plugin/plugin.js:7–22  ·  view source on GitHub ↗
(compiler)

Source from the content-addressed store, hash-verified

5
6class TransformVarToLetPlugin {
7 apply (compiler) {
8 compiler.hooks.emit.tap(pluginName, compilation => {
9 Object.keys(compilation.assets).forEach(item => {
10 // .source() 是获取构建产物的文本
11 // .assets 中包含构建产物的文件名
12 let content = compilation.assets[item].source()
13 let ast = $(content).replace('var $_$1 = $_$2', 'let $_$1 = $_$2')
14 content = ast.generate()
15 // 更新构建产物对象
16 compilation.assets[item] = {
17 source: () => content,
18 size: () => content.length,
19 }
20 })
21 })
22 }
23}
24
25module.exports = TransformVarToLetPlugin

Callers 2

$emitFunction · 0.80
$emitFunction · 0.80

Calls 3

$Interface · 0.85
replaceMethod · 0.65
generateMethod · 0.65

Tested by

no test coverage detected