{"id":20312486,"url":"https://github.com/sebastian-software/prepublish","last_synced_at":"2025-05-07T22:31:30.048Z","repository":{"id":57329864,"uuid":"65824866","full_name":"sebastian-software/prepublish","owner":"sebastian-software","description":"Simplifies the prepare step (bundling, transpiling, rebasing) during publishing NPM packages.","archived":true,"fork":false,"pushed_at":"2018-09-23T21:45:23.000Z","size":1642,"stargazers_count":21,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-04T08:06:06.030Z","etag":null,"topics":["babel","npm","postcss","prepare","prepublish","publish","rebase","release","rollup"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastian-software.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-16T13:59:29.000Z","updated_at":"2025-03-25T19:39:24.000Z","dependencies_parsed_at":"2022-09-06T20:30:45.467Z","dependency_job_id":null,"html_url":"https://github.com/sebastian-software/prepublish","commit_stats":null,"previous_names":["sebastian-software/prepublish-lib"],"tags_count":125,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-software%2Fprepublish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-software%2Fprepublish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-software%2Fprepublish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-software%2Fprepublish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastian-software","download_url":"https://codeload.github.com/sebastian-software/prepublish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252965577,"owners_count":21832917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","npm","postcss","prepare","prepublish","publish","rebase","release","rollup"],"created_at":"2024-11-14T18:06:19.346Z","updated_at":"2025-05-07T22:31:29.703Z","avatar_url":"https://github.com/sebastian-software.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# *Prepublish* \u003cbr/\u003e[![Sponsored by][sponsor-img]][sponsor] [![Version][npm-version-img]][npm] [![Downloads][npm-downloads-img]][npm] [![Build Status Unix][travis-img]][travis] [![Build Status Windows][appveyor-img]][appveyor] [![Dependencies][deps-img]][deps]\n\n*Prepublish* is a solution for simplifying pre-publishing typical JavaScript projects for publishing to NPM.\n\n[sponsor]: https://www.sebastian-software.de\n[deps]: https://david-dm.org/sebastian-software/prepublish\n[npm]: https://www.npmjs.com/package/prepublish\n[travis]: https://travis-ci.org/sebastian-software/prepublish\n[appveyor]: https://ci.appveyor.com/project/swernerx/prepublish/branch/master\n\n[sponsor-img]: https://badgen.net/badge/Sponsored%20by/Sebastian%20Software/692446\n[deps-img]: https://badgen.net/david/dep/sebastian-software/prepublish\n[npm-downloads-img]: https://badgen.net/npm/dm/prepublish\n[npm-version-img]: https://badgen.net/npm/v/prepublish\n[travis-img]: https://badgen.net/travis/sebastian-software/prepublish?label=unix%20build\n[appveyor-img]: https://badgen.net/appveyor/ci/swernerx/prepublish?label=windows%20build\n\n\n## Transpilers\n\n*Prepublish* relies on the [Babel Preset Edge](https://www.npmjs.com/package/babel-preset-edge) for producing forward-looking optimistic code for your code base.\n\n\n## Output Targets\n\n*Prepublish* produces exports of your sources depending on the entries of your packages `package.json`. It supports\nbuilding for *CommonJS* and well as with ES Modules (ESM). Just add the relevant entries to\nthe configuration.\n\n- CommonJS Output: `main`\n- ESM Output: `module`\n\nBasic Example:\n\n```json\n{\n  \"name\": \"mypackage\",\n  \"main\": \"lib/main.cjs.js\",\n  \"module\": \"lib/main.esm.js\"\n}\n```\n\nTo offer separate NodeJS and Browser builds use one of the following keys for the browser bundle: `browser` or `web`. These bundles are always exported as ES Modules (ESM) as we have the assumption that they are bundled by another tool like Webpack or Rollup before usage.\n\nExample:\n\n```json\n{\n  \"name\": \"mypackage\",\n  \"main\": \"lib/main.cjs.js\",\n  \"module\": \"lib/main.esm.js\",\n  \"browser\": \"lib/main.browser.js\"\n}\n```\n\n\n## Input Entries\n\nYou might wonder how to produce a browser bundle from a different input. This is actually pretty easy. Your package just have to follow this convention.\n\nThe files are looked up for an order. The first match is being used.\n\n### Entries for NodeJS targets\n\n- `src/node/public.js`\n- `src/node/export.js`\n- `src/node.js`\n- `src/server/public.js`\n- `src/server/export.js`\n- `src/server.js`\n- `src/server.js`\n- `src/public.js`\n- `src/export.js`\n- `src/index.js`\n\n### Sources for the Browser targets\n\n- `src/web/public.js`\n- `src/web/export.js`\n- `src/web.js`\n- `src/browser/public.js`\n- `src/browser/export.js`\n- `src/browser.js`\n- `src/client/public.js`\n- `src/client/export.js`\n- `src/client.js`\n\n### Sources for binary targets\n\n- `src/cli.js`\n- `src/binary.js`\n- `src/script.js`\n\n\n## Targetting ES2015\n\nYou are able to export modules for either ES5 compatible environments or for more modern platforms, too.\n\nNote: To use these non-standard bundle outputs requires some tweaks on the bundling phase of the application, too (e.g. in Webpack). This is because we are using non-standardized configuration keys in package.json. Typically just append either `:es2015` or `:modern` to your normal targets:\n\n- CommonJS Output for NodeJS with ES2015 kept intact: `main:es2015`\n- ES Modules Output for NodeJS with ES2015 kept intact: `module:es2015`\n- Browser Output as ES Modules with ES2015 kept intact: `browser:es2015`\n\nWhile `es2015` is exactly a requirement for the client to have full ES2015 support, `modern` is even more modern adding things from ES2017 to the list like `async`/`await`. Modern is regularly updated inside our [Babel Preset](https://github.com/sebastian-software/babel-preset-edge). It is by no way a never changing stable target.\n\nExample Configuration:\n\n```json\n{\n  \"name\": \"mypackage\",\n  \"main\": \"lib/main-cjs.js\",\n  \"module\": \"lib/main-esm.js\",\n  \"browser\": \"lib/main-browser.js\",\n  \"main:es2015\": \"lib/main.cjs.es2015.js\",\n  \"module:es2015\": \"lib/main.esm.es2015.js\",\n  \"browser:es2015\": \"lib/main.browser.es2015.js\"\n}\n```\n\nTo make sense of all these new modules it would help to produce two different outputs. One for classic browsers and one for modern browsers. ES2015 enabled features are [rapidly catching up in performance](https://kpdecker.github.io/six-speed/). Some features are pretty hard to rework for older browsers like Generators, Async/Await, or even Block Scope. Therefor we think there is no need for sending ES2015-capable clients the fully transpiled code down the wire. Keep in mind that you have to implement some basic client detection to send one or the other file to the matching client.\n\nBTW: The modern builds [make a lot of sense during development](https://medium.com/@gajus/dont-use-babel-transpilers-when-debugging-an-application-890ee528a5b3) as it results in shorter transpiler runtimes.\n\n\n## Binary Output\n\nAdditionally `prepublish` is capable in generating for binary targets.\n\nThis generates a `mypackage` binary which is generated from the matching source file.\n\nBinaries are generated from one of these source files:\n\n- `src/cli.js`\n- `src/binary.js`\n- `src/script.js`\n\nExample Configuration:\n\n```json\n{\n  \"name\": \"mypackage\",\n  \"bin\": {\n    \"mypackage\": \"bin/mypackage\"\n  }\n}\n```\n\nPrepublish automatically choses the matching NodeJS version from your `engines` configuration:\n\n```json\n\"engines\": {\n  \"node\": \"\u003e=6.0.0\",\n  \"npm\": \"\u003e=5.0.0\",\n  \"yarn\": \"\u003e=1.0.0\"\n}\n```\n\ninside your `package.json`. This example configuration targets any version of NodeJS matching at least the v6 capabilities.\n\n\n\n\n## Related Content\n\n- [Setting up multi-platform npm packages](http://2ality.com/2017/04/setting-up-multi-platform-packages.html)\n\n\n\n## Installation\n\n### NPM\n\n```console\n$ npm install --save-dev prepublish\n```\n\n### Yarn\n\n```console\n$ yarn add --dev prepublish\n```\n\n\n\n## Usage\n\n*Prepublish* comes with a binary which can be called from within your `scripts` section in the `package.json` file.\n\n```json\n\"scripts\": {\n  \"prepare\": \"prepublish\"\n}\n```\n\nThere is also some amount of parameters you can use if the auto detection of your library does not work out correctly.\n\n```\nUsage\n  $ prepublish\n\nOptions\n  --entry-node       Entry file for NodeJS target [default = auto]\n  --entry-web        Entry file for Browser target [default = auto]\n  --entry-binary     Entry file for Binary target [default = auto]\n\n  --output-folder    Configure the output folder [default = auto]\n\n  -x, --minified     Enabled minification of output files\n  -m, --sourcemap    Create a source map file during processing\n\n  --target-modern    Binaries should target Node v8 LTS instead of Node v6 LTS.\n\n  -v, --verbose      Verbose output mode [default = false]\n  -q, --quiet        Quiet output mode [default = false]\n```\n\n\n## License\n\n[Apache License; Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)\n\n## Copyright\n\n\u003cimg src=\"https://cdn.rawgit.com/sebastian-software/sebastian-software-brand/0d4ec9d6/sebastiansoftware-en.svg\" alt=\"Logo of Sebastian Software GmbH, Mainz, Germany\" width=\"460\" height=\"160\"/\u003e\n\nCopyright 2016-2018\u003cbr/\u003e[Sebastian Software GmbH](http://www.sebastian-software.de)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-software%2Fprepublish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastian-software%2Fprepublish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-software%2Fprepublish/lists"}