GithubHelp home page GithubHelp logo

nuba / prepublish Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sebastian-software/prepublish

0.0 2.0 0.0 609 KB

Simplifies the prepare step (bundling, transpiling, rebasing) during publishing NPM packages.

License: Apache License 2.0

JavaScript 98.86% CSS 1.14%

prepublish's Introduction

Prepublish
Sponsored by Version Downloads Build Status Unix Build Status Windows Dependencies

Prepublish is a solution for simplifying pre-publishing typical JavaScript projects for publishing to NPM.

Transpilers

Prepublish includes two transpiler configurations:

  • Buble: Blazing fast ES2015+ transpiler where the goal is to have lightweight runtime code, too.
  • Babel: Configuration of Babel transpiler. Supports all of ES2015/ES2016/ES2017. Plus some ES3 helpers for maximum engine compatibility. Plus Support for Object-Rest-Spread and Class Properties. The High-performance async engine with support for generators and async/await powered by fast-async is enabled by default. It requires nodent-runtime. Uses Transform-Runtime to externalize requirements to Polyfills. Resulting code needs all Polyfills for each library published with this tool. Typically by using services like polyfill.io or Babel Runtime aka CoreJS.

Output Targets

Prepublish produces builds depending on the entries of your packages package.json. It supports building for CommonJS and well as producing output with ES Modules (ESM). Just add the relevant entries to the configuration.

  • CommonJS Output: main
  • ES Module Output: module (jsnext:main is deprecated)

To offer separate NodeJS and Browser builds use one of the following keys for the browser bundle: browser or web or browserify. 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.

67m8BAQAg4mc

Classic vs. ES2015 vs. Modern

You are able to export modules for either ES2015 compatible environments or even more modern platforms, too. This happens in parallel and typically requires some heavy lifting on the bundling phase with Webpack, too. This is because we are using non-standardized configuration keys in package.json. Typically just append :modern to your normal targets:

  • CommonJS Output for NodeJS with ES2015 kept intact: main:modern
  • ES Modules Output for NodeJS with ES2015 kept intact: module:modern
  • Browser Output as ES Modules with ES2015 kept intact: browser:modern

While es2015 is exactly a requirement for the client to have full ES2015 support, modern is more flexible. We are thinking of updating what we understand as modern regularly. Currently modern is not fixed by specific features.

To 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. 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 modern 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.

BTW: The modern builds make a lot of sense during development as it results in shorter transpiler runtimes.

Articles

Installation

NPM

$ npm install --save-dev prepublish

Yarn

$ yarn add --dev prepublish

Usage

Prepublish comes with a binary which can be called from within your scripts section in the package.json file.

"scripts": {
  "prepare": "prepublish"
}

There is also some amount of parameters you can use if the auto detection of your library does not work out correctly.

Options
  --entry-node      Entry file for NodeJS target [default = auto]
  --entry-web       Entry file for Browser target [default = auto]
  --entry-binary    Entry file for Binary target [default = auto]

  --output-folder   Configure the output folder [default = auto]

  -t, --transpiler  Chose the transpiler/config to use. Either "babel" or "buble". [default = babel]
  -x, --minified    Enabled minification of output files
  -m, --sourcemap   Create a source map file during processing

  -v, --verbose     Verbose output mode [default = false]
  -q, --quiet       Quiet output mode [default = false]

Contributing

  • Pull requests and stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests ($ npm test).

License

Apache License; Version 2.0, January 2004

Copyright

Sebastian Software GmbH Logo

Copyright 2016-2017
Sebastian Software GmbH

prepublish's People

Contributors

swernerx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.