我正在尝试将express-babelify-middleware
与 FeathersJS 一起使用,并且错误显示在浏览器控制台中:
ReferenceError: main_run 未定义
我认为这意味着 babelify 不工作或者我使用不正确,因为 main_run 在我的 html 文件中 src 的全局命名空间中。
这是我使用羽毛生成的结构的设置:
公共/index.html:
<!DOCTYPE html>
<html>
<head>
<title>babelify test</title>
<script src="main.js"></script>
<script>
main_run()
</script>
</head><body>
<p>Testing feathers with babelify</p>
</body></html>
公共/main.js
const external_module = require('./test')
function main_run(){
external_module()
}
公共/test.js
module.exports = function(){
console.log("Hello world for an external module")
}
在 src/app.js 的 .uses 中:
...
const babelify = require('express-babelify-middleware')
...
app.use(compress())
.options('*', cors())
.use(cors())
//the line that is not working:
.use('/main.js', babelify( path.join(app.get('public'), 'main.js') ))
.use(favicon( path.join(app.get('public'), 'favicon.ico') ))
.use('/', serveStatic( app.get('public') ))
当我访问 localhost:3030/main.js 时,我可以看到该文件,但这些函数看起来是在它们自己的函数中,所以我不知道如何进入该函数。