![](/img/trans.png)
[英]How to expose 'require' to the browser when using browserify from within gulp?
[英]Expose global variable when using Browserify
我使用Browserify並希望將D3.js與雷達圖表組件一起使用。
import 'd3';
import 'radar-chart-d3';
雷達圖表組件返回錯誤Uncaught ReferenceError: d3 is not defined
。
我嘗試使用insertGlobalVars
選項:
browserify: {
bundleName: 'main.js',
prodSourcemap: false,
insertGlobalVars: {
d3: function(file, dir) {
return 'require("d3")';
}
}
}
但是,這並沒有改變任何情況。 我知道我可以在雷達圖.js文件的頂部添加require('d3')
,但我想避免這種情況。
還有什么方法可以將d3
變量暴露給全局范圍,以便其他文件可以使用d3
。
把它放在package.json
:
"eslintConfig": {
"globals": {
"d3": true
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.