Lukáš Horák
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# How to Open source FE package 101 ## Initialize Log into the NPM ```sh $ npm login # or $ npm adduser ``` Create package.json with guide ```sh $ npm init # or $ yarn init ``` > Tip: Use `-y` arg to answer yes to all questions in guide We distinguish between unscoped and scoped packages and also between private and public packages. If you wish to add some cool fancy badges, look at [shields.io](https://shields.io) , pick some and add them into you README.md. #### Unscoped packages Unscoped packages are always public. Has the name not starting with `@` like `react`, `lodash`, etc. #### Scoped packages Packages scoped to user or organization which has to be created in NPM. Scoped packages can be public or private but for private packages you must have paid organization account at NPM. Scoped packages are **private by default** so for public open source packages you need to pass `--access public` when publishing to the registry. ## Prepare We can use [`pre` and `post`](https://docs.npmjs.com/cli/v7/using-npm/scripts#pre--post-scripts) scripts for any script defined in `scripts` section, eg. `prebuild`, `postbuild`. You can use [`prepublishOnly`](https://docs.npmjs.com/cli/v7/using-npm/scripts#life-cycle-scripts) script to run just before publishing to npm registry. ### Transpilation Babel has an option [`--copy-files`](https://babeljs.io/docs/en/babel-cli#copy-files) that can be used to copy files that are not about to transpile. #### Targets For Frontend packages you'll usually target two kinds of sources: CJS and ESM (some packages also support UMD) * **CJS** - Transpiled CommonJS compatible sources. No ES6 features, no `import`s & `exports`s * **ESM** - Transpiled ES Modules compatible sources. No ES6 features, uses `import`s & `exports`s. This kind of sources is usually leveraged by bundlers to tree shake unused sources. * **UMD** - Stands for Universal Module Definition. Transpiled sources that supports various module systems, see [examples](https://github.com/umdjs/umd/tree/master/templates). It's not an [easy topic](https://dev.to/remshams/rolling-up-a-multi-module-system-esm-cjs-compatible-npm-library-with-typescript-and-babel-3gjg) and it's [getting complicated even more](https://2ality.com/2019/10/hybrid-npm-packages.html) as Node.JS 12 supports MJS (ESM native implementation) natively now. There is several package.json fields used to refer different sources types: * [**`main`**](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main)- It is a primary entry point for modules system. Should always point to CommonJS compatible sources. * [**`module`**](https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c) - Not an official field, rather a [proposal](https://github.com/nodejs/node-eps/blob/4217dca299d89c8c18ac44c878b5fe9581974ef3/002-es6-modules.md#51-determining-if-source-is-an-es-module) understand by code bundlers like [rollup](https://github.com/rollup/rollup/wiki/pkg.module) or [`webpack`](https://www.jonathancreamer.com/how-webpack-decides-what-entry-to-load-from-a-package-json/). Should point to an ES modules sources. * **`browser`** - Point to package bundle for its usage in browser. Webpack looks first for the `module`, and lastly `main`. ### Files You should control what will be published inside package and **never publish any sensitive information** like private keys, passwords, etc. > If it happens you accidently publish what you didn't intend, there is still way [how to unpublish](https://docs.npmjs.com/unpublishing-packages-from-the-registry#how-to-unpublish) but sooner you realize and make it, the easier it will be. #### Blacklisting When publishing NPM uses file `.npmignore` to determine which files won't be included into the package. File `.npmignore` uses same syntax as `.gitignore`. If there is no `.npmignore` in a repo, `.gitignore` is used to determine omitted files and folders. Remember that `.npmignore` has precedence over `.gitignore` and only one of them is used. If there is something in `.gitignore` you want to make part of package, create `.npmignore` and fill it according to your needs. There is a list of [files are ignored by default](https://docs.npmjs.com/cli/v7/using-npm/developers#keeping-files-out-of-your-package) and should never get published like `node_modules`, `.DS_Store`, `.git`, `.npmrc`, `npm-debug.log`, etc. On the other hand, these files are never ignored so you don't need to list them in the ignore file: `package.json`, `README`, `CHANGELOG`, `LICENSE`, them `main` field file. #### Whitelisting You can also choose inverse approach and select files to include in the package, using [`files` field](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files) in `package.json`. > Files included with the `files` field cannot be excluded through .npmignore or .gitignore. ### Version Evey good package **must follow** [semantic versioning](https://semver.org) principles when creating new package version. New package release requires `version` field in `package.json` to be changed. We can use `version` command for that > Note: NPM recommends [first package version to be `1.0.0`](https://docs.npmjs.com/about-semantic-versioning) but it's not an obligation. #### [`npm version`](https://docs.npmjs.com/cli/v7/commands/npm-version) `npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]` * Bumps version in `package.json` (also in `package-lock.json` or `npm-shrinkwrap.json` if present). * create a version commit * create a version tag #### [`yarn version`](https://classic.yarnpkg.com/en/docs/cli/publish) `yarn version` starts a guide for setting new version, alternatively you can use syntax similar to `npm version` `yarn version [--new-version <version> | --major | --minor | --patch | --premajor | --preminor | --prepatch | --prerelease [--preid <pre-identifier>] ]` Makes the same 3 steps as the `npm version`. You can hook into the version lifecycle with these `package.json#scripts`: `preversion`, `version`, `postversion`. We utilize the `version` script for [updating changelog](https://github.com/AckeeCZ/jerome/blob/master/package.json#L24). > Tip: Use `.yarnrc` to change version commit message with `version-git-message "🔖 Version %s"` or tag prefix with `tag-version-prefix ""`. https://stackoverflow.com/questions/29738381/how-to-publish-a-module-written-in-es6-to-npm ## Release ### Test package If you're not sure what will be published into the registry, test packing it ```sh $ npm pack $ open package_name.tgz ``` If you want to test package installation ```sh $ npm install ./path_to_package_dir # or $ yarn add ./path_to_package_dir ``` ### Publish Release to the NPM registry is done with command ```sh $ npm publish ``` which pack and release into standard public NPM registry `https://registry.npmjs.org/` > Note: Be aware that `yarn publish` also prompts for new version. When publishing new version you can specify [release tag](). By default **`latest` tag is used** with standard publish. But we can also use `alpha` or `beta` tags to mark version as a prerelease and make sure it won't be accidentally installed. You can see package latest, beta, and alpha versions in [list of versions](https://www.npmjs.com/package/@ackee/antonio). ```sh $ npm publish --tag beta ``` ### Manual publish Just run the publish command from the command line. ### Automated publish By CI (Github, Gitlab) usually triggered on push of new version tag. You need to have an [NPM access token](https://docs.npmjs.com/creating-and-viewing-access-tokens) (of type Automation) to do this. #### Travis Defined by `travis.yml` file in repository root. There is already a guide about [How to setup Travis pipeline](https://frontend-cookbook.ack.ee/#/pages/GithubPipeline). #### GH actions Defined by yaml workflow definition in `.github/workflows` directory. An example is in [`lokse` repository](https://github.com/AckeeCZ/lokse/tree/master/.github/workflows) On Github you can use Travis CI or GH Actions. We've been using Travis CI for a long time but now time has come to start using GH Actions. Reasons to use GH Actions over Travis CI: * They're integrated into the Github UI whereas Travis is a standalone service on different url with differen UI * There are more flexible, workflows consists of actions and there is an actions marketplace * Easier to set up, we can use one `NPM_TOKEN` across our repositories * Executing GH actions is faster ### Create GH release It's a good practise to fill in also [Github Release](https://docs.github.com/en/github/administering-a-repository/about-releases) with release notes once you publish a new version since developers also looks for what changed right there. ## Other ### More entry points If you need you can utilize pattern with more than one package.json in the repo as [used in `@ackee/jerome`](https://github.com/AckeeCZ/jerome/blob/master/antd/package.json) ```sh my-npm-pkg/ package.json # pkg.main points to index src/ index.js alternative-index.js alternative/ package.json # pkg.main points to alternative-index ``` ### Package deprecation In case you decide package to be obsolete and not usable, use command ```sh $ npm deprecate ``` to mark it deprecated. ### Monorepos In our terms monorepo means one repository holding several packages that are published separately. How to works with monorepos is for standalone topic as setuping it is a bit complicated. You're gonna find useful tools like [Lerna](https://github.com/lerna/lerna) and yarn [workspaces](https://yarnpkg.com/lang/en/docs/workspaces/). You can take an inspiration from [Resizin js respository](https://github.com/AckeeCZ/resizin-js/).

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully