Created
April 4, 2020 19:43
-
-
Save Ryuno-Ki/1c1a66b13fb0f6ce08a117701c7e0f37 to your computer and use it in GitHub Desktop.
Bundling Node.js module with bare return on top level, c.f. https://twitter.com/liran_tal/status/1245626369112821763
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import semver from 'semver' // I want this to be bundled in | |
import './node_modules/abc/abc.js' // this is vanilla JS, I expect this to be imported in the global scope | |
import * as myData from './mydata.json' // this is just json data I'm working with | |
async function myOwnThing() { | |
return some_data_object_here; | |
} | |
return myOwnThing(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "gist", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"esm": "3.2.25", | |
"rollup": "2.3.2", | |
"rollup-plugin-terser": "5.3.0", | |
"semver": "7.1.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { terser } from "rollup-plugin-terser"; | |
const options = { | |
parse: { | |
bare_returns: true | |
} | |
}; | |
module.exports = { | |
input: "index.js", | |
plugins: [terser(options)] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically, It should be possible to bundle
index.js
into a node module, but thereturn myOwnThing();
trips up many bundlers.Running
terser -p 'bare_returns' index.js
creates a minified file, but the file is never passed into the rollup plugin for terser.