我使用rollup.js,这是我的代码:
import d3 from 'd3';
console.log(d3);
这是我的配置:
import nodeResolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
export default {
input: 'src/test.js',
external:[
'd3'// external
],
output: {
file: 'dist/test.js',
format: 'umd',
paths: {
d3: 'https://d3js.org/d3.v4.min'// d3 paths
}
},
plugins: [
nodeResolve(),
commonjs()
]
};
这是结果js:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('https://d3js.org/d3.v4.min')) :
typeof define === 'function' && define.amd ? define(['https://d3js.org/d3.v4.min'], factory) :
(global = global || self, factory(global.d3));
}(this, function (d3) { 'use strict';
...
}));
然后,当我使用此js时,d3
是未定义的。
我看到require
和defined
未定义。
怎么了?