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

vite-stimulus-initializer

v1.0.2

Published

Initializer for Stimulus on Vite with configurable Naming Conventions based on the filename

Downloads

103

Readme

DEPRECATED! Replacement: @csedl/stimulus-initializer

On Rails we are familiar with nice and handy conventions that saving a lot of time.

At this tutorial i showed a way for integrating Svelte and Stimulus for handy tools for simplifying our javascript process.

On the Handbook Stimulus has shown a default way for declaring keys based of the controller filenames. While this is a safe way i found this double-dashes silly and the namespaces could be shortened. Of course, if you want to have a naming where you can be 100% there is never a conflict, please stay at this default way. That is what this module, by default, does.

For a smarter naming this module adds some options.

This module corresponds with vite-svelte-initializer.

If, a conflict occours, it alerts on console with a log entry and on Browser with a alert.

Assume a file structure like so:

frontend/javascript/

- components
   |-- articles
      |-- select-controller.js
- global
   |-- select-controller.js

default: the safe way

frontend/entrypoints/application.js

import { initStimulus } from "vite-stimulus-initializer";

const comps = import.meta.glob('../javascript/components/**/*-controller.js', { eager: true })
initStimulus(comps, 2)

=> "2", the second parameter tells that the first two parts of the part (".." and "javascript" are excluded from namespacing, so it generates the tagname:

components--articles--select, which can be applied as custom element in the view by <div data-controller="components--articles--select" > .. </div>, and a global--select tag.

optional: the smarter way

for making this more handy, you can:

frontend/entrypoints/application.js

import { initStimulus } from "vite-stimulus-initializer";

const apps = import.meta.glob('../javascript/components/**/*-controller.js', { eager: true })
initStimulus(apps, 2, { debug: true, exclude: ['components'], folderSeparator: '-' })

this prints out on console (because of debug: true):

  • STIMULUS IDENTIFIER «articles-select» from: ./components/views/admin/sub/next-controller.js
  • STIMULUS IDENTIFIER «global-select» from: ./global/select-controller.js

and having no more double-dash because of folderSeparator: '-'

The exclude: [..] is only applied for the level-3, which means: the first two levels are excluded completely because of second parameter, and the next is targeted by exclude.

and generates the corresponding tags.

Hope you enjoy!