In Node, we now use a CommonJS build with external dependencies, rather than inlining the dependencies as is done with the UMD bundle. Thus, Node now automatically defers to the dependent’s main entry; in the case of d3-request, that means it inherits the XMLHttpRequest polyfill. A slight wrinkle is that Rollup doesn’t correctly re-export the d3.event symbol if the dependencies are not inlined. However, this is fixed by patching the CommonJS build and replacing the event export with a getter. This commit also removes the rollup-plugin-json dependency, and instead generates a tiny ES6 module to export the version field from package.json.
This commit is contained in:
Родитель
58c872235b
Коммит
40951a7af3
2
index.js
2
index.js
|
@ -1,6 +1,6 @@
|
|||
export {
|
||||
version
|
||||
} from "./package.json";
|
||||
} from "./build/version";
|
||||
|
||||
export {
|
||||
bisect,
|
||||
|
|
|
@ -18,14 +18,15 @@
|
|||
"name": "Mike Bostock",
|
||||
"url": "http://bost.ocks.org/mike"
|
||||
},
|
||||
"main": "build/d3.js",
|
||||
"main": "build/d3.node.js",
|
||||
"browser": "build/d3.js",
|
||||
"jsnext:main": "index",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mbostock/d3.git"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "mkdir -p build && rollup -c -o build/d3.js -- index.js",
|
||||
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"export var version = \\\"\" + require(\"./package.json\").version + \"\\\";\\n\");' > build/version.js && rollup -c -o build/d3.js -- index.js && rollup -e `node -e 'process.stdout.write(Object.keys(require(\"./package.json\").dependencies).join(\",\"));'` -f cjs -- index.js | grep -v '^exports.event =' > build/d3.node.js && echo '\nObject.defineProperty(exports, \"event\", {get: function() { return d3Selection.event; }});' >> build/d3.node.js",
|
||||
"test": "faucet `find test -name '*-test.js'`",
|
||||
"prepublish": "npm run test && uglifyjs build/d3.js -c -m -o build/d3.min.js && rm -f build/d3.zip && zip -j build/d3.zip -- LICENSE README.md build/d3.js build/d3.min.js",
|
||||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && cp -v build/d3.js ../d3.github.com/d3.v${VERSION}.js && cp -v build/d3.min.js ../d3.github.com/d3.v${VERSION}.min.js && cd ../d3.github.com && git add d3.v${VERSION}.js d3.v${VERSION}.min.js && git commit -m \"d3 ${VERSION}\" && git push"
|
||||
|
@ -33,7 +34,6 @@
|
|||
"devDependencies": {
|
||||
"faucet": "0.0",
|
||||
"rollup": "0.25",
|
||||
"rollup-plugin-json": "2",
|
||||
"rollup-plugin-node-resolve": "1",
|
||||
"tape": "4",
|
||||
"uglify-js": "2"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import json from "rollup-plugin-json";
|
||||
import node from "rollup-plugin-node-resolve";
|
||||
|
||||
export default {
|
||||
plugins: [node({jsnext: true}), json()],
|
||||
plugins: [node({jsnext: true})],
|
||||
moduleName: "d3",
|
||||
format: "umd"
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче