From 297bcea49bf431f650dfeed515cbec6b02b00af1 Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Mon, 2 Aug 2021 04:03:13 +0530 Subject: [PATCH] Generate bundle.min.js in Node.js install script (#3794) --- platform/nodejs/main.js | 8 ++++++++ platform/nodejs/package.json | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/nodejs/main.js b/platform/nodejs/main.js index 0cd292955..50f25427c 100644 --- a/platform/nodejs/main.js +++ b/platform/nodejs/main.js @@ -146,6 +146,14 @@ function reset() { snfe.reset(); } +// rollup.js needs module.exports to be set back to the local exports object. +// This is because some of the code (e.g. publicsuffixlist.js) sets +// module.exports. Once all included files are written like ES modules, using +// export statements, this should no longer be necessary. +if (typeof module !== 'undefined' && typeof exports !== 'undefined') { + module.exports = exports; +} + export { FilteringContext, enableWASM, diff --git a/platform/nodejs/package.json b/platform/nodejs/package.json index acad0bc14..4339f7ea1 100644 --- a/platform/nodejs/package.json +++ b/platform/nodejs/package.json @@ -5,7 +5,7 @@ "type": "module", "main": "main.js", "scripts": { - "install": "node install.js", + "install": "node install.js && rollup main.js --file bundle.min.cjs --format cjs --context global --plugin terser", "test": "node test.js" }, "repository": { @@ -22,5 +22,9 @@ "bugs": { "url": "https://github.com/gorhill/uBlock/issues" }, - "homepage": "https://github.com/gorhill/uBlock#readme" + "homepage": "https://github.com/gorhill/uBlock#readme", + "dependencies": { + "rollup": "^2.55.1", + "rollup-plugin-terser": "^7.0.2" + } }