是否有可能使用Node.jsdynamic脚本文件注入html?
我试图从特定path获取*.js
并将脚本注入到index.html
文件中。
我用下面的node.js
代码来检索目录中的文件。
function walkSync(currentDirPath, callback) { var fs = require('fs'), path = require('path'); fs.readdirSync(currentDirPath).forEach(function (name) { var filePath = path.join(currentDirPath, name); var stat = fs.statSync(filePath); if (stat.isFile()) { callback(filePath, stat); } else if (stat.isDirectory()) { walkSync(filePath, callback); } }); } var componentsFilePath = []; walkSync("app/scripts/", function (filePath, stats) { if (filePath.indexOf(".js") > 0) { componentsFilePath.push(filePath); } }); console.log("scripts : " + componentsFilePath);
现在,我面临着注入的挑战。
不可能将上面的脚本文件注入到html
页面。
感谢您的支持。