【发布时间】:2016-10-06 07:51:15
【问题描述】:
我不确定我哪里出错了:
{ Error: ENOENT: no such file or directory, open '../dist/index.html'
at Error (native)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '../dist/index.html' }
我在我的代码中添加了console.log("Build HTML error") 以查看错误是否触发并且确实如此。我还使用console.log($.html()); 来查看是否生成了正确的 HTML,并且确实如此。
我的代码:
fs.readFile(__dirname + '/../app/index.html', 'utf8', (err, markup) => {
if (err) {
console.log("grab HTML error");
return console.log(err);
}
const $ = cheerio.load(markup);
console.log($.html());
$('head').prepend('<link rel="stylesheet" href="styles.css">');
fs.writeFile('../dist/index.html', $.html(), 'utf8', err => {
if (err) {
console.log("Build HTML error");
return console.log(err);
}
console.log('index.html written to /dist'.green);
});
});
如您所见,我将dist 目录放在正确的位置,并且生成并构建了从webpack 生成的其他文件
项目结构:
【问题讨论】:
-
在需要“路径”后尝试使用 path.resolve()
标签: javascript node.js express ecmascript-6