Skip to content

Commit

Permalink
rollup: better browser module name for scoped package
Browse files Browse the repository at this point in the history
  • Loading branch information
mhyfritz committed Oct 17, 2019
1 parent 7bebdfe commit 1954401
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ import babel from "rollup-plugin-babel";
import * as pkg from "./package.json";
import camelCase from "camelcase";

/*
generate module name for in-browser use
`module` => `module`
`my-module` => `myModule`
`@scope/module` => `scopeModule`
`@scope/my-module` => `scopeMyModule`
`@my-scope/my-module` => `myScopeMyModule`
*/
let nameBrowser = pkg.name;
if (/^@.+\//.test(nameBrowser)) {
nameBrowser = nameBrowser.substring(1).replace("/", "-");
}
nameBrowser = camelCase(nameBrowser);

const config = {
input: "src/index.js",
output: {
name: camelCase(pkg.name),
name: nameBrowser,
format: "umd",
banner: `// ${pkg.homepage} v${
pkg.version
Expand Down

0 comments on commit 1954401

Please sign in to comment.