Skip to content

Commit

Permalink
feat: webpack debug
Browse files Browse the repository at this point in the history
  • Loading branch information
okbug committed Nov 21, 2021
1 parent 866221d commit 535fa4c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 49 deletions.
51 changes: 50 additions & 1 deletion learnWebpack/my-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,53 @@ module.exports = 'title';

所以在development模式下面保留.r .d .o 等方法的缩写

pull requlest 1 告一段落
pull requlest 1 告一段落







## webpack中的tapable

这是一个类似发布订阅的库


```js
import { SyncHook } from 'tapable'

let syncHook = new SyncHook();

// tab就是发布订阅中的on 参数是 eventName和cb

syncHook.tap('just a name', (payload) => {
console.log('callback', payload);
})

// call就是触发回调,并且可以作为参数,并且不用传入eventName

syncHook.call('zhufeng')
```

### 实现tapable


最简版

```js
class SyncHook {
constructor() {
this.taps = [];
}

tap(name, fn) {
this.taps.push(fn);
}

call(...args) {
this.taps.forEach(tap => tap(...args))
}
}
```

24 changes: 12 additions & 12 deletions learnWebpack/webpack-analysis/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "debug webpack",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js"
}
]
}
// {
// "version": "0.2.0",
// "configurations": [
// {
// "type": "node",
// "request": "launch",
// "name": "debug webpack",
// "cwd": "${workspaceFolder}",
// "program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js"
// }
// ]
// }
25 changes: 1 addition & 24 deletions learnWebpack/webpack-analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,5 @@

# 调试webpack工作流程

使用vscode调试

在项目根目录添加 `.vscode` 文件夹,并且添加配置文件:`launch.json`

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "debug webpack",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js"
}
]
}


```

注意上面`program`的webpack路径要对应自己node_modules下的路径(因为有可能多个版本webpack 导致件夹带上版本号)

然后新建一个文件
暂无文字

24 changes: 12 additions & 12 deletions learnWebpack/webpack-analysis/debugger.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const webpack = require('webpack');
const config = require('./webpack.config');



const compiler = webpack(config);
console.log(compiler)
debugger
const compiler = webpack(config);
// console.log(compiler)
compiler.run((err, state) => {
console.log(err);
console.log(state.toJson({
assets: true,
chunks: true,
modules: true,
entries: true
}))
})
// console.log(state.toJson({
// assets: true,
// chunks: true,
// modules: true,
// entries: true
// }))
})

// console.log(compiler.run)
console.log(compiler.hooks.done);

0 comments on commit 535fa4c

Please sign in to comment.