webpack打包注意事项
打包protobuf时导出全局变量(使用webpack), 注意文件的编码为ANSI、UTF(一定要无BOM), 否则webpack复制文件会产生乱码(js错误)
packet_config.js
var goog = require('google-protobuf'); var global = Function('return this')(); goog.exportSymbol('aa.bb.cc', null, global); aa.bb.cc = function () { alert('aaaa'); }
webpack packet_config.js packet.js
index.html
<script src="packet.js"></script>
<script type="text/javascript"> aa.bb.cc(); </script>