我在Rails4中使用plotly.js,现在我只有lib文件/vendor/assets/javascripts/plotly.js,并且需要在application.js (//= require plotly)中使用它。Ploly.js大约是1MB,所以我想减小它的大小。在github页面上有一个如何做到这一点的instruction:
// in custom-plotly.js
var plotlyCore = require('plotly.js/lib/core');
// Load in the trace types for pie, and choropleth
plotlyCore.register([
require('plotly.js/lib/pie'),
require('plotly.js/lib/choropleth')
]);
module.exports = plotlyCore;
// Then elsewhere in your code:
var Plotly = require('./path/to/custom-plotly');我不知道我应该把这段代码放在哪里,以便只服务于库的一些模块,而不是整个库。
如果不能使用内置功能,你会建议如何解决这个问题?
发布于 2016-03-10 16:45:17
这是针对npm模块和Modularizing monolithic JS projects的说明。Rails中没有nodejs解释器。
Rails可以通过minify减少这个js文件的大小。
https://stackoverflow.com/questions/35910719
复制相似问题