nextjs默认把node_modules下一个js作为一个公共的js来处理,webpack就不会去分析node_modules下一个js的依赖了,会导致很多在node_modules中的依赖拿取不到,你可以尝试
webpack(config) {
if (config.externals) {
const includes = [/locale/]
config.externals = config.externals.map((external) => {
if (typeof external !== 'function') return external
return (ctx, req, cb) => {
return includes.find((include) =>
req.startsWith('.') ? include.test(path.resolve(ctx, req)) : include.test(req)
)
? cb()
: external(ctx, req, cb)
}
})
}
return config
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…