我需要在我的 javascript 代码中使用类似功能的 Node.js 功能require()
,所以我正在使用 watchify,但它仍然给我错误Uncaught ReferenceError: require is not defined at jsfile.js:3
,尽管 watchify 捆绑代码并检查到bundle.js
文件中,如果我在 localhost 上进行测试,一切都会容易得多,但我已经在 heroku 中托管了我的网站,但我不知道命令队列,我应该先执行 git 命令(git add .
git commit -m "commit"
git push heroku master
)然后 watchify(npm run watch
)还是先 watchify,然后再执行 git 命令?还是其他地方有问题?这是我的 package.json 代码(部分)
"scripts": {
"start": "node ilia.js",
"watch": "npx watchify ./public/jsfile.js -o ./public/bundle.js"
},
"devDependencies": {
"watchify": "^3.11.1"
}
并在我的 html 中链接 javascript 文件(bundle.js、jsfile.js)
<script src="jsfile.js"></script>
<script src="bundle.js"></script>
所以我该怎么做?