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

@marko/vite

v4.1.10

Published

A Marko plugin for Vite

Downloads

8,251

Readme

A Marko plugin for Vite.

Installation

npm install @marko/vite

Example config

import { defineConfig } from "vite";
import marko from "@marko/vite";
export default defineConfig({
  plugins: [marko()],
});

Base paths

When deploying an application under a nested public path, use Vite's base option to specify a path to prefix all assets. This option can also be specified with the BASE_URL environment variable.

If the base path is not static, see the basePathVar option for handling more advanced cases.

Browser asset references

With @marko/vite when a static relative path is used for certain native tag attributes, the relative asset will be imported and processed by Vite.

As an example, with the following template, the logo.svg will be imported and processed as if it was a import at the root of the file.

<img src="./logo.svg">

// Would produce a Vite processed asset and update the src, eg with the following output
<img src="/assets/logo-TwEWmgMb.svg">

Most common image, media, and font filetypes are transformed automatically but some file types such as .js and .css files will not be. Generally these should be imported directly and not rendered as markup. To force the transformation of a path, add ?url to it. You can see the list of elements and their attributes which are processed here.

Linked Mode

By default this plugin operates in linked mode (you can disabled this by passing linked: false as an option). In linked mode the plugin automatically discovers all of the entry .marko files while compiling the server, and tells Vite which modules to load in the browser.

With this you do not create .html files for Vite, it's Marko all the way down! Scripts, styles and other content that would have been injected into the .html files is instead automatically injected into your .marko templates.

In this mode you must use the Vite SSR API.

Here's an example using express.

import { createServer } from "vite";

const app = express();
let loadTemplate;

if (process.env.NODE_ENV === "production") {
  // Use Vite's built asset in prod mode.
  loadTemplate = () => import("./dist");
} else {
  // Hookup the vite dev server.
  const vite = await createViteServer({
    server: { middlewareMode: true }
  });

  app.use(vite.middlewares);
  loadTemplate = () => vite.ssrLoadModule("./template.marko");
}

app.get("/", async (req, res) => {
  const template = (await loadTemplate()).default;
  // When the template is loaded, it will automaticall have `vite` assets inlined.
  template.render({ hello: "world" }, res);
);

app.listen(3000);

For a more real world setup check out our vite express example app.

Options

options.babelConfig

You can manually override Marko's Babel configuration by passing a babelConfig object to the @marko/vite plugin. If no babel configuration is specified, babel related config files will not be considered.

marko({
  babelConfig: {
    presets: ["@babel/preset-env"],
  },
});

options.runtimeId

In some cases you may want to embed multiple isolated copies of Marko on the page. Since Marko relies on some window properties to initialize this can cause issues. For example, by default Marko will read the server rendered hydration code from window.$components. In Marko you can change these window properties by rendering with { $global: { runtimeId: "MY_MARKO_RUNTIME_ID" } } as input on the server side.

This plugin exposes a runtimeId option produces output that automatically sets $global.runtimeId on the server side and initializes properly in the browser.

marko({ runtimeId: "MY_MARKO_RUNTIME_ID" });

options.linked

Set this to false to opt out of linked mode. When this is false, the plugin will only handle resolving and transforming .marko files.

options.basePathVar

Set this to variable/identifier which all asset base paths should be prefixed with. All asset paths used by Vite will either be relative (if possible) or prefixed with this identifier. The identifier must be defined as a string before any other server code executes.

First configure @marko/vite.

marko({ basePathVar: "__MY_ASSET_BASE_PATH__" });

Then ensure you set that variable at runtime.

globalThis.__MY_ASSET_BASE_PATH__ = getAssetUrl(); // Note this must end with a `/`.
require("./dist/index.mjs"); // load the built vite app.

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.