function loader(source) { let reg = /url\((.+?)\)/g; let current; let pos = 0; let arr = [`let lists = [];`]; while (current = reg.exec(source)) { let [matchUrl, p] = current; let index = reg.lastIndex - matchUrl.length; arr.push(`lists.push(${JSON.stringify(source.slice(pos, index))})`); pos = reg.lastIndex; arr.push(`lists.push("url("+require(${p})+")")`); } arr.push(`lists.push(${JSON.stringify(source.slice(pos))})`); arr.push(`module.exports = lists.join('')`); return arr.join('\r\n'); } module.exports = loader;
webpack手写loader ----css-loader
猜你喜欢
转载自blog.csdn.net/qq_28473733/article/details/95484816
今日推荐
周排行