手写一个loader
module.exports = function (source) {
return source.replace("dell", "hahahahhahha")
const callback = this.async()
seTimeout(()=>{
const result = source.replace("dell", "hahahahhahha")
callback(null,result)
})
}
resolveLoader:{
modules:['node_modules','./loaders']
}
module: {
rules: [
{
test: /\.js$/,
use: [path.resolve(__dirname, './loaders/loader.js')]
use: ['./loaders/loader.js')]
}
]
},
手写一个plugin
class CopyRightWebpackPlugin {
constructor(options) {
}
apply(compiler) {
compiler.hooks.emit.tapAsync('CopyRightWebpackPlugin', (compilertion, cb) => {
compilertion.assets['CopyRight.txt'] = {
source: function () {
return 'this is my first plugins yeyeye'
},
size: function () {
return 30
}
}
cb()
})
}
}
module.exports = CopyRightWebpackPlugin
const CopyRightWebpackPlugin = require('./plugins/copyright-webpack-plugin')
new CopyRightWebpackPlugin({
name: 'liuhuang'
})
bundler源码编写