GithubHelp home page GithubHelp logo

kustomzone / snowpack-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fredkschott/snowpack

1.0 3.0 0.0 85 KB

:package: :sparkles: Install npm dependencies that run directly in the browser. No Browserify, Webpack or import maps required.

License: MIT License

JavaScript 25.50% TypeScript 74.50%

snowpack-js's Introduction

Logo

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

Logo


npm on Dec 6, 2018 - "JavaScript in 2018 is somewhat notorious for requiring a lot of tooling to get going, which is quite a reversal from the situation in 2014... All of our survey respondents would like to see less tooling [and] less configuration required to get started."


@pika/web brings that nostalgic, 2014 simplicity to 2019 web development:

  • Simple 💪 No bundlers required. Load modern, ESM packages natively in the browser.
  • Flexible 🧘‍♂️ Handles dependency trees of any size, even ones that includes legacy Common.js packages.
  • HTTP/2 Optimized ⚡️ No more huge, cache-busting bundles. Browsers only download deps when they change.

Quickstart

npm install --save-dev @pika/web
yarn add --dev @pika/web
# 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 htm from "htm";
+ import { createElement, Component } from "/web_modules/preact.js";
+ import htm from "/web_modules/htm.js";

# 3. Run that file directly in the browser and see the magic! 
✨ ~(‾▿‾~)(~‾▿‾)~ ✨

# (Optional) If you already use Babel to build your application, skip "Step 2" and let our plugin rewrite your imports automatically:
echo '{"plugins": [["@pika/web/assets/babel-plugin.js"]]}' > .babelrc

# (Optional) Add a package.json "prepare" script to run @pika/web on every npm install:
{"scripts": {"prepare": "pika-web"}}

By default, @pika/web will install all package.json dependencies with an ES "module" entrypoint to the web_modules/ directory. @pika/web is able to handle any legacy Common.js/Node.js transitive dependencies in your dependency tree, however the top-level dependencies (the ones that you import directly) must have a "module" entrypoint.

┻┳|
┳┻| _
┻┳| •.•) 💬 "Tip: Use pikapkg.com to find modern, web-ready packages on npm :)"
┳┻|⊂ノ
┻┳|

Performance

When @pika/web installs your dependencies, it bundles each package into a single ESM JavaScript file. Shared chunks are created for any transitive dependencies shared between them, if they exist. Example: If @pika/web installs 10 npm packages into web_modules/, you can expect 10 JavaScript files and maybe a few additional shared chunks.

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 that 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."

More testing is obviously needed, but at this early stage we feel confident extrapolating the following: When served with HTTP/2, @pika/web installations perform better in production than single "vendor" JavaScript bundles and most custom dependency bundling strategies due to the comparable load performance + more efficient cache usage.

Why?

Pika's mission is to make modern JavaScript more accessible by making it easier to find, publish, install, and use modern packages on npm. You can learn more the Pika project at https://www.pikapkg.com/about.

Options

package.json Options

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

  • "webDependencies": You can define an optional whitelist of "webDependencies" in your package.json manifest. This is useful if your entire "dependencies" object is too large or contains unrelated, server-only packages that may break @pika/web.
  "dependencies": {
    "htm": "^1.0.0",
    "preact": "^8.0.0",
    /* A mix of other server and frontend dependencies */
  },
  "@pika/web": {"webDependencies": ["htm", "preact"]},

CLI Options

  • --strict: Only install pure ESM dependency trees. Great for purists, or anyone who doesn't want to deal with transitive Common.js and Node.js-only dependencies.
  • --optimize: (Planned, coming soon!) Minify installed dependencies.

Special Thanks: Rollup

@pika/web is powered internally by Rollup. We believe that bundlers shouldn't be a requirement for modern web 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.

snowpack-js's People

Contributors

0xflotus avatar fredkschott avatar

Stargazers

 avatar

Watchers

 avatar  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.