的index.html:
<script>
document.addEventListener("DOMContentLoaded", function() {
...
getXYCookieValue()
...
}
</script>
<body>
...
<script src="bundle.js" type="text/javascript"></script>
</body>
的WebPack-配置:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: {
entry: __dirname + '/src/cookieHandler.js'
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build'),
},
}
cookieHandler.js
function getXYCookieValue() {
// returns xy cookie value
}
server.js
app.use(express.static(path.join(__dirname, 'build')));
如果我获取localhost:3000 / bundle.js,则会返回该文件,并在其中看到getXYCookieValue()函数。但是,当我尝试在index.html中使用它时,我得到了
Uncaught ReferenceError: getXYCookieValue is not defined
错误。
我在这里缺少什么?