因此,经过深入研究,该问题现已解决。看起来我在我的非优化包 app.js 中查看的第 1665 行不是我需要查看的(很明显,因为列索引很远)。
因此,我决定输出 FuseBox 正在处理的捆绑生成代码,它实际上是不同的。这是我在uglifyBundle function 内的node_modules/fuse-box/quantum/plugin/BundleWriter.js 中添加的行,用于输出内容,以便我可以清楚地阅读。
fs.writeFile('bundle.txt', bundle.generatedCode);
bundle.txt 中的输出是问题所在,我的实际 TypeScript 代码如下所示:
// bundle.txt line 1665
this.wholesalerSettings = [object Object]
// actual project code
constructor() {
this.wholesalerSettings = process.env.WHOLESALERSETTINGS;
this.API = this.setHostUrl();
}
所以我查看了我的 fuse.ts 文件,发现我没有正确解析 json 对象。
public get wholesalerSettings()
{
const wholesaler = require(`./src/~/wholesalers/${this.wholesaler}/config.json`);
return JSON.stringify(wholesaler);
}
// then down in the environment plugin
EnvPlugin({
WHOLESALERSETTINGS: this.wholesalerSettings,
IMAGE_PATH: this.imagePath
}),
一旦我用JSON.stringify 正确解析了对象,它就可以完美地工作,因为process.env.WHOLESALERSETTINGS 现在是一个JSON 字符串而不是一个对象。
我第一次真正处理 devops 的东西,但很有趣,同时压力很大。我想我学到的主要内容是当您处理工具和第三方工具(FuseBox 使用 uglify-js)时,您需要仔细查看该工具的输入,而不是像我一样的输出一开始。