Created
November 15, 2020 19:13
-
-
Save mwdchang/eafca0fa974583482d5f4fd10fd66fac to your computer and use it in GitHub Desktop.
Basic JS lib setup
This file contains 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": "jslib-test", | |
"version": "1.0.0", | |
"description": "Testing library packaging", | |
"main": "dist/cjs/main.js", | |
"module": "dist/esm/index.js", | |
"scripts": { | |
"build": "rollup -c", | |
"dev": "rollup -c -w" | |
}, | |
"files": [ | |
"dist" | |
], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"@rollup/plugin-node-resolve": "^10.0.0", | |
"rollup": "^2.33.1", | |
"rollup-plugin-terser": "^7.0.2" | |
} | |
} |
This file contains 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 { nodeResolve } from "@rollup/plugin-node-resolve"; | |
import { terser } from "rollup-plugin-terser"; | |
import pkg from "./package.json"; | |
const input = ["src/main.js"]; | |
export default [ | |
{ | |
// UMD | |
input, | |
plugins: [ | |
nodeResolve(), | |
terser(), | |
], | |
output: { | |
file: `dist/${pkg.name}.min.js`, | |
format: "umd", | |
name: "myLibrary", // this is the name of the global object | |
esModule: false, | |
exports: "named", | |
sourcemap: true, | |
}, | |
}, | |
{ | |
input, | |
plugins: [ | |
nodeResolve, | |
terser() | |
], | |
output: [ | |
{ | |
dir: "dist/esm", | |
format: "esm", | |
exports: "named", | |
sourcemap: true, | |
}, | |
{ | |
dir: "dist/cjs", | |
format: "cjs", | |
exports: "named", | |
sourcemap: true, | |
} | |
] | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment