博客主页:@丘比特惩罚陆
欢迎关注:点赞收藏⭐留言✒
系列专栏:web前端、嵌入式、笔记专栏
加入社区: 灌水乐园
人生格言:选对方向,每走一步都是进步!
✒️欢迎大佬指正,一起学习!一起加油!希望大家能小手一动,帮忙点个赞!
资源邮箱:[email protected];微信:lss0901lili1130
目录
1.如何编写一个Loader(一)
2.如何编写一个Loader(2)
3.如何编写一个Plugin
const path = require( 'path;
module.exports = {
mode: 'development',
entry: {
main: './src/index.js'},
output: {
path: path.resolve(_dirname, 'dist ' ),filename: '[name] . js'
}
module.exports = function(source) {
return source.replace( 'dell', 'dellLee ' );}
module: {
rules:[{
test:/\js/ ,
use: [
path.resolve(__dirname, './loaders/ replaceLoader.
]
}
use: [
{
loader: path.resolve(_ dirname,'./loaders/ repl.options:{
name: 'lee'}
}
module.exports = function(source){
return source.replace( 'dell', this.query.name);上
const loaderUtils = require( ' loader-utils' );module.exports = function(source) {
const options = loaderUtils.getOptions (this);return source.replace( 'dell', options.name);}
this.callback(null,result)1
const loaderUtils = require( 'loader-utils' );
module.exports = function(source) {
const options = loaderUtils.get0ptions(this);
const callback = this.async();
setTimeout(=>{
const result = source.replace( 'dell', options.name);
callback( result);
},1000);
}
resolveLoadef: {
modules: [ 'node_modules', './loaders ']
}
module: {
rules: [{
test:/\.js/ ,
use: [
{
loader: 'replaceLoader' ,
},
{
loader: 'replaceLoaderAsync',
options: {
name: 'lee'}
},]
]}
class CopyrightwebpackPlugin {
constructor() {
}
apply(compiler){}
}
I
module.exports =CopyrightwebpackPlugin;|
tapAsync( 'CopyrightwebpackPlugin', ( compilation,cb)
compilation.assets[ copyright.txtj]={
source:function({
return "copyright by dell lee'},
size: function(){
return 21;l
}
;cb();})
}