我试图使用WebPack来包含“摊牌”。问题是摊牌将需要(“fs”)并检查返回值。这使得WebPack引发错误。如何让webpack跳过一个模块,如果它不存在
看来应该可以配置Webpack来生成一个shim,以便调用require(“fs”)将返回false。
也许这些技术的一个可能的工作:http://webpack.github.io/docs/shimming-modules.html
这里的Showdown.js代码。如果我在节点模块目录中注释掉这些代码,问题就解决了。但是,应该有更好的方法。
//
// Automatic Extension Loading (node only):
//
if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') {
var fs = require('fs');
if (fs) {
// Search extensions folder
var extensions = fs.readdirSync((__dirname || '.')+'/extensions').filter(function(file){
return ~file.indexOf('.js');
}).map(function(file){
return file.replace(/\.js$/, '');
});
// Load extensions into Showdown namespace
Showdown.forEach(extensions, function(ext){
var name = stdExtName(ext);
Showdown.extensions[name] = require('./extensions/' + ext);
});
}
}
为了记录在案,摊牌是现在回到了新的维护者和pull请求已经被合并。 – pdeschen 2015-01-22 19:11:55