zxdfe / FE-Interview

Every step counts
34 stars 1 forks source link

第55题:loader和plugin的区别是什么? #56

Open zxdfe opened 1 year ago

zxdfe commented 1 year ago

Loader

module.exports = function(input) { 
    const callback = this.async();

        // webpack5内置了loaderUtils.getOption,用this.query就能接收参数
        console.log(this.query) 
        const result =  source.replace('webpack5', this.query.name)
        // 同步用this.callback 返回
        this.callback(null, result)
        callback(null, input + input); 
};

Plugin