在做一个webpack的demo的时候创建一个自定义的loader
,对loader进行配置的时候设置了size:20
,看的教程以及别的教程的博客都是用的getOptions
方法来获取options的配置项。
{
test:/\.md$/i,
// use:'./loader/markdown-loader'
use:[
'html-loader',
//marked将md转换为html
// './loader/markdown-loader'
{
loader:'./loader/markdown-loader',
options:{
size:20
}
}
]
}
const loaderUtils = require('loader-utils')
module.exports = function(source) {
//获取loader配置项
const options = loaderUtils.getOptions(this)
console.log('ooooo' + options);
const html = marked.parse(source)
return html
}
但是现在使用这个方法进行打包的时候就会报没有getOptions方法的错误。
在官方文档中方法好像只剩下了
但是好像没有替换的方法,后来注意到方法 interpolateName 的参数中有一个query
的参数然后就直接拿来试了一下。
module.exports = function(source) {
//获取loader配置项
// const options = this.query
console.log('ooooo' + this.query.size);
console.log('123'+source);
const html = marked.parse(source)
return html
}
确实能够输出配置的 size:20
虽然不知道是不是正解,但是目前就是好像可以拿到配置的options了。
版权声明:本文为weixin_51524737原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。