Skip to content

Instantly share code, notes, and snippets.

@Ryuno-Ki
Created April 4, 2020 19:43
Show Gist options
  • Save Ryuno-Ki/1c1a66b13fb0f6ce08a117701c7e0f37 to your computer and use it in GitHub Desktop.
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
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();
{
"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"
}
}
import { terser } from "rollup-plugin-terser";
const options = {
parse: {
bare_returns: true
}
};
module.exports = {
input: "index.js",
plugins: [terser(options)]
};
@Ryuno-Ki
Copy link
Author

Ryuno-Ki commented Apr 4, 2020

Basically, It should be possible to bundle index.js into a node module, but the return 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment