npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

a2-hello-rollup

v1.0.7

Published

my rollup study

Downloads

2

Readme

rollup-study

ビルドツール rollup の勉強

基本事項

  • browser 用には webpack、node.js のライブラリ用には rollup とかの使い分けらしい
    • よくわかってないけれど
  • npx rollup -c が最小コマンドかな(コンフィグファイルが必要, -c は省略できなかった)
  • rollup.config.js で config が記載できる(default 名)
    • 詳細は後述
  • using plugins
  • rollup api: rollup.rollup, rollup.watch がありカスタマイズが可能

todos

  • [ ] publish 後、install したとき default export ができてない
    • こう書かないといけない: import * as anypackage from 'a2-hello-rollup'

hands up

npm install -D rollup

コンパイル

--format オプションによりそれぞれに向けたコンパイルが可能

# for browser
npm run rollup src/main.js --file dist/browserBundle.js --format iife
# for node
npm run rollup src/main.js --file dist/nodeBundle.js --format cjs
# for umd (browser node)
npm run rollup src/main.js --file dist/umdBundle.js --format umd --name "myBundle"

note: それぞれの出力結果

config 設定

公式(サンプルあり): Configuration Files

  • 配列で export することで、複数の src 指定及び設定が可能
  • typescript で書きたい場合: --configPlugin typescript とつける
  • (args) => rollupConfig を export することで、args にコマンドラインの引数を取得して分岐が可能

typescriipt 対応

typescript でトランスパイルし、npm publish 後に利用できるようにする(最低限)

yarn add -D @rollup/plugin-typescript typescript tslib

tsconfig.json

{}

rollup.config.js

  • typescript へのオプション設定は, tsconfig.json に上書きされる
  • declaration, declarationDir は d.ts を出力する設定
const typescript = require('@rollup/plugin-typescript')

export default {
  input: 'src/index.ts',
  preserveModules: true, // チャンクファイルに分割して出力(.d.tsファイル出力)
  output: {
    // file: 'dist/index.js',
    dir: 'dist', // preserveModules: true の場合、fileではなくdirで設定
    format: 'cjs'
  },
  plugins: [
    typescript({
      declaration: true, // タイプファイルの出力ON
      declarationDir: 'dist/@types' // タイプファイルの出力先
    })
  ]
}

package.json

private の解除と、types の設定(typescript での type 補完が有効になる)

{
  ...
  "main": "dist/index.js",
  "types": "dist/@types/index.d.ts",
  ...
  "private": false,
}