Skip to main content

手写一个 Loader

实现一个 markdown loader、一个清理目录的 plugin、一个统计编译时长的 plugin

使用

{
test: /\.js$/
use: [
{
loader: path.resolve('path/to/loader.js'),
options: {
/* ... */
}
}
]
}

loader 范例

module.exports = function (source) {
const options = getOptions(this)
return source.replace(/jirengu/, options.name)
}

参考文章:https://juejin.cn/post/6882895689773383694