我正在尝试使用 WebPack 来包含 "showdown"。问题在于 showdown 会 require("fs") 并检查返回值。这会导致 WebPack 抛出错误。
看起来应该可以配置 Webpack 生成一个 shim,以便对 require("fs") 的调用将返回 false。
也许这些技术之一可能有效:http://webpack.github.io/docs/shimming-modules.html 以下是 Showdown.js 代码。如果我注释掉节点模块目录中的此代码,则问题得到解决。但是,应该有更好的方法。
看起来应该可以配置 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);
});
}
}