非常简单的反应装载机
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'static/js/');
var APP_DIR = path.resolve(__dirname, 'js');
var config = {
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel'
},
]
},
entry: APP_DIR + '/app.jsx',
output: {
path: BUILD_DIR,
filename: 'app.js'
}
};
module.exports = config;
然后我使用下面的内容提供结果。它设置了一些从golang后端传递的全局变量,然后加载了bundle。
<script type="text/babel">
window.AuthURL = "{{.AuthURL}}";
window.CODE = GetCode("code");
window.APPVERSION = '{{.VERSION }}';
</script>
<script src="static/js/app.js"></script>
app.jsx看起来像
console.log(window);
console.log(window.Infinity);
console.log(window.APPVERSION);
我在控制台上得到这样的东西
我设置的变量在浏览器上突出显示,但对webpack不可见。我究竟做错了什么?我可以获得所需的行为吗?