因此,我有一个使用已汇总的d3的函数,该函数相应地具有一个mousemove
事件
本质上,我想要鼠标相对于页面的位置,所以我这样称呼:
import * as d3 from 'd3'
...
export function foo() {
d3.select("html").on('mousemove',()=>{
console.log(d3.mouse(d3.select('html').node()))
})
}
汇总后,我会得到current is null
TypeError: current is null
堆栈跟踪是我对mousemove
的{{1}}函数,它指向mouse
sourceEvent
有想法吗?
function sourceEvent() {
var current = event, source;
while (source = current.sourceEvent) current = source;
return current;
}
从import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify-es';
import minimist from 'minimist';
import pkg from './package.json';
const argv = minimist(process.argv.slice(2));
const config = {
input: 'src/entry.js',
output: {
name: pkg.name,
exports: 'named',
extend: true,
external: ['d3'],
globals: {
d3: 'd3'
},
},
plugins: [
babel({
exclude: 'node_modules/**',
externalHelpers: true,
// runtimeHelpers: true,
}),
nodeResolve({
mainFields: ['module', 'main', 'jsnext']
}),
commonjs({
// non-CommonJS modules will be ignored, but you can also
// specifically include/exclude files
include: 'node_modules/**', // Default: undefined
// search for files other than .js files (must already
// be transpiled by a previous plugin!)
extensions: [ '.js', '.coffee' ], // Default: [ '.js' ]
namedExports: {
'node_modules/d3/dist/d3.node.js': [
'selection', 'mouse', 'select', 'interpolateRgbBasis',
'median', 'min', 'max', 'scaleLinear', 'easeExp', 'extent', 'event',
'easeSin', 'selectAll', 'keys', 'interpolateRgb', 'descending', 'line',
'curveBasis', 'histogram', 'ascending', 'sourceEvent'
],
// 'node_modules/d3/d3.js': ['selection', 'mouse', 'select'],
// 'node_modules/d3-selection/src/selection/index.js': ['selection']
},
// sometimes you have to leave require statements
// unconverted. Pass an array containing the IDs
// or a `id => boolean` function. Only use this
// option if you know what you're doing!
ignore: [ 'conditional-runtime-dependency' ]
})
],
onwarn: function ( message ) {
if (message.code === 'CIRCULAR_DEPENDENCY') {
return;
}
console.error(message);
}
};
// Only minify browser (iife) version
if (argv.format === 'iife') {
config.plugins.push(uglify());
}
export default config;
中删除'event'
会产生汇总事件
namedExports
我也尝试添加:
{ code: 'MISSING_EXPORT',
missing: 'event',
importer: 'src/modules/legends/numeric-legend.js',
exporter: 'node_modules/d3/dist/d3.node.js',
message:
"'event' is not exported by 'node_modules/d3/dist/d3.node.js'",
url: 'https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-',
...
}
到我的出口,但这也不起作用