Install npm packages that run natively in the browser.
Last updated 2 months ago by fredkschott .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @pika/web 
SYNC missed versions from official npm registry.


@pika/web • Install npm dependencies to run directly in the browser. No Browserify, Webpack or import maps required.

  • Simple ???? No app bundlers required. Just run once at install time.
  • Flexible ????‍♂️ Handles dependency trees of any size, even ones that includes legacy Common.js packages.
  • HTTP/2 Optimized ⚡️ No more huge JS bundles. Browsers only download dependencies when they change.


npx @pika/web                            # Run once.
npm install -g @pika/cli && pika install # Run multiple.
npm install --dev @pika/web              # Optional: Install locally to use "pika install" in any package.json scripts


# 1. Run @pika/web in your project:
    $ npx @pika/web
# 2. Replace all NPM package imports in your web app with web-native URLs:
-   import { createElement, Component } from "preact";
+   import { createElement, Component } from "/web_modules/preact.js";
-   import htm from "htm";
+   import htm from "/web_modules/htm.js";

# 3. Run your code directly in the browser and see the magic!
    ✨ ~(‾▿‾~)(~‾▿‾)~ ✨
# Optional: Using Babel? Skip "Step 2" and let our plugin rewrite your imports automatically:
    echo '{"plugins": [["@pika/web/assets/babel-plugin.js"]]}' > .babelrc
# Optional: Install @pika/web locally so that it runs faster next time...
    npm install --save-dev @pika/web
# Optional: ...and then add a "prepare" script to your package.json to have it run after every install:
    {"scripts": {"prepare": "pika install"}}

@pika/web installs npm packages as single .js files to a new web_modules/ directory. If your dependency exports an ES "module" entrypoint in its package.json manifest, it is supported. Even if it internally depends on other npm packages (even legacy Common.js packages) @pika/web should be able to handle it.

Bundling packages on a per-module basis like this makes it easy to build a web application that runs fast and caches well. Updating a single dependency won't force a complete re-download of your web application. More on performance below.

┳┻| _
┻┳| •.•) ???? "Tip: Use pika.dev to search 70,000+ modern, web-ready packages on npm"



When @pika/web installs your dependencies, it bundles each package into a single ESM JavaScript file. Example: If @pika/web installs 10 npm packages into web_modules/, you can expect 10 JavaScript files and maybe 1-2 additional files of code shared between them.

Max Jung's post on "The Right Way to Bundle Your Assets for Faster Sites over HTTP/2" is the best study on HTTP/2 performance & bundling we could find online. @pika/web's installation most closely matches the study's moderate, "50 file" bundling strategy. Jung's post found that for HTTP/2, "differences among concatenation levels below 1000 [small files] (50, 6 or 1) were negligible."

Browser Support

@pika/web installs ES Module (ESM) dependencies from npm, which run wherever ESM syntax is supported. This includes 86%+ of all browsers in use today: All modern browsers (Firefox, Chrome, Edge, Safari) going back at least a year, but notably not IE11 or UC Browser for Android.

Additionally, @pika/web runs all dependencies through Babel via @preset/env to transpile any language features not yet supported in most modern browsers. You can customize how dependencies are transpiled by setting your own "browserslist" key in your package.json manifest:

  /* package.json - Recommended target for ESM-supporting browsers (default) */
  "browserslist": ">0.75%, not ie 11, not op_mini all"


Note: All package.json options are scoped under the "@pika/web" property.

  • "webDependencies": (Recommended) Configure which packages to install with @pika/web. Without this, @pika/web will just try to install every package in your "dependencies" config. That behavior is great for getting started but it won't warn you if an expected package fails to install.
  • "namedExports": (Optional) If needed, you can explicitly define named exports for any dependency. You should only use this if you're getting "'X' is not exported by Y" errors without it. See rollup-plugin-commonjs for more info.
  "dependencies": { "htm": "^1.0.0", "preact": "^8.0.0", /* ... */ },
  "@pika/web": {
    "webDependencies": [
      "preact/hooks", // A package within a package
      "unistore/full/preact.es.js" // An ESM file within a package

A Note on React

React is not yet published with ES Module support, and the way it's build makes it impossible to bundle as an entrypoint (Error: '__moduleExports' is not exported by node_modules/react/index.js). However, it is still possible to use React with @pika/web thanks to @sdegutis's @reactesm project & npm/yarn's alias feature:

npm install react@npm:@reactesm/react react-dom@npm:@reactesm/react-dom
   yarn add react@npm:@reactesm/react react-dom@npm:@reactesm/react-dom

This command installs ESM versions of the latest react & react-dom, which @pika/web will then use when it installs your web_modules/ directory. This works with any ESM-compatible React libraries as well!

import React, { useState } from './web_modules/react.js';

A Note on JSX

Remember that JSX won't run in any browser. To use JSX with @pika/web:

  1. Use Babel to build your src/ directory to an output lib/ directory, and load that in the browser.
  2. Use a JSX-like library like Jason Miller's htm that can run in the browser.

Special Thanks: Rollup

@pika/web is powered internally by Rollup. We believe that bundlers shouldn't be a requirement for modern web app development, but none of this would be possible without the awesome work done by Rollup contributors. If you use and enjoy our software, consider contributing back to Rollup on Open Collective.

Current Tags

  • 0.6.1                                ...           latest (2 months ago)
  • 0.5.0-pre.3                                ...           next (5 months ago)

20 Versions

  • 0.6.1                                ...           2 months ago
  • 0.6.0                                ...           2 months ago
  • 0.5.3                                ...           3 months ago
  • 0.5.2                                ...           3 months ago
  • 0.5.1                                ...           3 months ago
  • 0.5.0                                ...           3 months ago
  • 0.4.4                                ...           4 months ago
  • 0.5.0-pre.3                                ...           5 months ago
  • 0.5.0-pre.2                                ...           5 months ago
  • 0.5.0-pre.1                                ...           5 months ago
  • 0.4.3                                ...           5 months ago
  • 0.4.2                                ...           7 months ago
  • 0.4.1                                ...           8 months ago
  • 0.4.0                                ...           8 months ago
  • 0.3.2                                ...           8 months ago
  • 0.3.1                                ...           8 months ago
  • 0.3.0                                ...           8 months ago
  • 0.2.0                                ...           9 months ago
  • 0.1.4                                ...           9 months ago
  • 0.1.3                                ...           9 months ago
Maintainers (1)
Today 1
This Week 5
This Month 6
Last Day 1
Last Week 1
Last Month 16
Dependencies (18)

Copyright 2014 - 2016 © taobao.org |