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

@metamodern/svelte-render

v3.0.3

Published

A friendly Jamstack-focused build tool for Svelte apps

Downloads

23

Readme

@metamodern/svelte-render

A friendly Jamstack-focused build tool for Svelte apps

I created this utility to scaffold build configurations for my Svelte projects. Because I focus on modern static sites and client-side apps that can be deployed with Netlify, Sapper includes a lot of infrastructure for server-side development that I don't need. Svelte Kit is around the corner as a next-gen replacement for Sapper, but it may not be production-ready in the immediate future, so I will be maintaining this CLI tool until I have a solid replacement.

Features

Here are some of the features that svelte-render adds on top of a starter Rollup configuration:

  • Assumes a sensible directory structure, but allows customization
  • Includes a CLI script with flags for common rendering options
  • Includes essential plugins out of the box
  • Supports a JavaScript configuration file to import additional plugins, etc.
  • Comes with a built-in Babel configuration (with option not to transpile)
  • Supports render hooks to automate additional build steps
  • ES modules everywhere – never require() again!

Install

npm i @metamodern/svelte-render

CLI Usage

The CLI script is released as an ES module only. Minimum Node.js version is 14 (latest LTS as of release date).

npx svelte-render [context] [--key=value]

# default to process.cwd() as context
cd project
npx svelte-render [--key=value]

# skip production optimizations
npx svelte-render --development

# just output HTML from the entry file
npx svelte-render --client=0 --noCss

# specify a custom directory structure
npx svelte-render --src=. --dist=public

# specify the path to your config file
# ** if not at ./render.config.js **
npx svelte-render --configFile=./config/svelte-render.js

Configuration file

Options may be specified using a configuration file. The file should use ES module import/export syntax. Its default export should be a function that takes an object containing command-line options as its arugment and returns an object specifying additional options to pass to the rendering function.

The config file is expected to be found at ./render.config.js (relative to context), but a custom path can be specified from the command line as shown above.

See below for a list of all options that may be passed to the rendering function.

JavaScript API & Configuration Options

The JavaScript API is released as an ES module only. CommonJS require() is not supported.

The module's default export is a function with the following parameters:

async function(context: string, {
  src = 'src',
  assets = 'assets',
  dist = 'dist',
  entry = 'index.svelte',
  client = 'client.js',
  noCss = false,
  development = false,
  transpile = !development,
  rollupInputPlugins = [],
  rollupInputOptions = {},
  compilerOptions = {},
  sveltePreprocess = {},
  svelteOptions = {},
  terserOptions = {},
  browsers = 'defaults',
  babelPresets = [['@babel/preset-env', {
    targets: browsers,
    corejs: 3,
    useBuiltIns: 'usage',
  }]],
  babelPlugins = [],
  babelOptions = {},
  before,
  onRender,
  after,
} = {}): Promise<number> // returns 0 on success

Required

  • context: path to the project's root directory

Note: The context argument is only required when using the JavaScript API. When using the CLI script, context defaults to process.cwd().

Configuring the Directory Structure

The following options may be specified as file names or paths and will be resolved relative to context.

  • src: parent directory of entry and client source files
  • assets: directory of static assets to be copied to dist
  • dist: public directory where web files will be served
  • entry: a Svelte file to be pre-rendered as the initial view (ignored when the development flag is on)
  • client: a JavaScript source file that will be rolled-up as the client-side script (to render static HTML only, set client to false and don't use the development flag)

Setting Rendering Option Flags

  • noCss: don't output CSS generated from Svelte <style> blocks
  • development: skip production optimizations (pre-rendering markup, transpiling JS, minifying JS & CSS)
  • transpile: use Babel to transform/polyfill client-side JS as needed for target browsers (turned on by default, unless the development flag is passed)

Advanced Rendering Options (for Rollup, Svelte, Terser)

  • rollupInputPlugins: input plugins (official, community) to pass to Rollup
  • rollupInputOptions: additional input options to pass to Rollup
  • compilerOptions: compiler options to pass to rollup-plugin-svelte (under the compilerOptions key)
  • sveltePreprocess: preprocessing functions to pass to rollup-plugin-svelte (under the preprocess key)
  • svelteOptions: additional options to pass to rollup-plugin-svelte
  • terserOptions: options to pass to rollup-plugin-terser

Transpiling Options (for Babel)

  • browsers: a valid Browserslist configuration
  • babelPresets: presets to pass to Babel
  • babelPlugins: plugins to pass to Babel
  • babelOptions: additional options to pass to Babel

Note: These options are ignored when transpile is set to false

Render Hooks

Render hooks are functions to execute in tandem with the main rendering function. Each function will be passed the resolved context and the full options object. Async functions are supported.

  • before: function to invoke and await before rendering
  • onRender: function to invoke and await in parallel with Rollup build of client/entry scripts
  • after: function to invoke and await after rendering

License

© 2020 Daniel C. Narey

ISC License