简体   繁体   English

Vue,Webpack,DC.js和Finally Crossfilter

[英]Vue, Webpack, DC.js, and Finally Crossfilter

I'm trying to build a proof of concept application that uses DC.js to bring in some static data and visualize it. 我正在尝试构建一个概念验证应用程序,它使用DC.js引入一些静态数据并将其可视化。 We've decided to use Vue.js as our framework and Webpack as our build tool. 我们决定使用Vue.js作为我们的框架,使用Webpack作为构建工具。 I have included D3.js, Crossfilter, and DC.js in the base config. 我在基本配置中包含了D3.js,Crossfilter和DC.js.

resolve: {
    extensions: ['', '.js', '.vue'],
    fallback: [path.join(__dirname, '../node_modules')],
    alias: {
      'src': path.resolve(__dirname, '../src'),
      'assets': path.resolve(__dirname, '../src/assets'),
      'components': path.resolve(__dirname, '../src/components'),
      'd3': path.resolve(__dirname, '../bower_components/d3/d3.min.js'),
      'crossfilter': path.resolve(__dirname, '../bower_components/crossfilter/crossfilter.min.js'),
      'dc': path.resolve(__dirname, '../bower_components/dcjs/dc.js') // using unminified version to look at exactly where the error is coming from
    }
}

And in the file with the actual visualization components like so. 并在具有实际可视化组件的文件中如此。

var d3 = require('d3')
var cf = require('crossfilter')
var crossfilter = cf.crossfilter
var dc = require('dc')

However DC.js requires crossfilter to work and it hangs on the first instance of of a call to crossfilter within the context of DC.js. 但是DC.js需要交叉过滤器才能工作,它会挂起在DC.js上下文中调用crossfilter的第一个实例。 Further more after I load the page I can no longer access crossfilter in the console however I can access D3 . 加载页面后,我再也无法访问控制台中的crossfilter ,但我可以访问D3 What is bringing D3.js in as a global require that isn't bringing crossfilter in as one? 是什么让D3.js成为一个全球性的需求,而不是将crossfilter作为一个整体?

Is there some configuration that I'm overlooking here? 我在这里有一些配置吗?

So getting Crossfilter and DC.js to work with webpack and vue is possible. 因此,让Crossfilter和DC.js与webpack和vue一起工作是可能的。 I had to make modifications to the DC.js source to get it work. 我必须对DC.js源进行修改才能使其正常工作。

  1. In webpack.base.conf.js you'll need to add the following to module exports. webpack.base.conf.js您需要将以下内容添加到模块导出中。

    plugins: [ new webpack.ProvidePlugin({ d3: 'd3', crossfilter: 'crossfilter', dc: 'dc' }) ]

This makes these three libraries available globally. 这使得这三个库在全球范围内可用。 Without requiring them. 不要求他们。

  1. If Like me you were using ESlint you'll need to add the following to eslintrc.js to have it ignore the fact that you're not requiring these files. 如果像我一样你使用ESlint,你需要将以下内容添加到eslintrc.js ,让它忽略你不需要这些文件的事实。

    'globals': { 'd3': true, 'dc': true, 'crossfilter': true }

  2. Finally in DC.js right after the 'use strict'; 最后在'use strict';之后的DC.js中'use strict'; declaration you'll need to set up crossfilter. 声明你需要设置crossfilter。

    var crossfilter = crossfilter.crossfilter;

While this isn't a perfect answer it at least has me able to render charts. 虽然这不是一个完美的答案,但它至少让我能够渲染图表。 Now if I could figure out how to redefine the global Crossfilter package as crossfilter.crossfilter I would feel like I had a complete answer. 现在,如果我能弄清楚如何将全局Crossfilter包重新定义为crossfilter.crossfilter,我觉得我有一个完整的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM