我有自己的json-loader,我想使用它而不是内置的加载器。这曾经在webpack-3中工作;在webpack-4中,我的加载器被调用,但结果被传递给内置加载器,然后错误输出,因为它被提供的是JS源,而不是json。如何防止被调用的json-loader被调用?我的webpack.cofig.ts看起来像这样:
import * as webpack from 'webpack'
import * as path from 'path'
const config = {
mode: 'production',
node: { fs: 'empty' },
resolveLoader: {
alias: { 'custom-json-loader': 'zotero-plugin/loader/json' },
},
module: {
rules: [ { test: /\.json$/, use: [ 'custom-json-loader' ] } ],
},
// ...
}
export default config
你必须告诉webpack你的加载器发出javascript而不是json。为此,您必须将type: "javascript/auto"
添加到您的加载程序配置:
module: {
rules: [
{
test: /\.json$/,
use: [ 'custom-json-loader' ] ,
type: "javascript/auto"
}
]
}