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-plugin-files-loader

v1.1.1

Published

A vite plugin that reads file content in batches

Downloads

23

Readme

vite-plugin-files-loader

npm npm

A vite plugin that reads file content in batches.

Emmmm....

You can use import.meta.glob to achieve similar functionality. It can also use alias and { as: 'raw' } to import corresponding files. This package may not mean much to you.

Usage

  1. NPM Install

    npm i vite-plugin-files-loader -D
  2. Vite Config

    // vite.config.js
    import FilesLoader from 'vite-plugin-files-loader'
    
    export default {
      plugins: [
        FilesLoader({
          paths: './demos',
          resolveChildrenBase: 'src',
          enableResolveLongChildren: true,
        })
      ],
    }
  3. Usage

    /**
     * |-demos
    *    |-button
    *        |-src
    *          |-basic
    *            |-index.html
    */
    import DEMOS from 'virtual:files-loader' // =>  /demos/..
    import BUTTON_DEMOS from 'virtual:files-loader/button' // => /demos/button/src/..
    import BUTTON_BASIC_DEMOS from 'virtual:demo-loader/button/basic' // => /demos/button/src/basic/..
    

    If you want to use dynamicImport option, you can to use the following function to resolve/import the content of the file

    import { resolveImportPaths, resolveImportFiles } from 'vite-plugin-files-loader'
    const demos = resolveImportPaths(DEMOS)
    const childDemos = resolveImportFiles(BUTTON_DEMOS)
    // virtual:files-loader
    {
      "__default": [
        {
          "name": "button",
          "children": [
            {
              "name": "basic",
              "children": [
                {
                  "name": "index.html",
                  "content": "...",
                  "language": "html"
                }
              ]
            }
          ]
        },
        {
          "name": "index.html",
          "content": "...",
          "language": "html"
        }
      ]
    }
    // virtual:files-loader/button
    [
        {
          "name": "basic",
          "children": [
            {
              "name": "index.html",
              "content": "...",
              "language": "html"
            }
          ]
        }
    ]
    // virtual:demo-loader/button/basic
    [
        {
          "name": "index.html",
          "content": "...",
          "language": "html"
        }
    ]

Options

export interface FilesLoaderPluginOptions {
  /**
   * Relative paths will be based on root
   * @default process.cwd()
   */
  root?: string
  /**
   * ✅ Support vite configuration alias
   * ⚠️ If paths is string, it will be set to __default in output
   * ⚠️ If the path is relative it will be based on root
   * @default {}
   * @example { __default: './src/content', '@components': '@components' }
   */
  paths?: Record<string, string> | string
  /**
   * @default [/^\./]
   */
  exclude?: (string | RegExp)[]
  /**
   * @default ['.html', '.css', '.js', '.ts']
   */
  extensions?: string[]
  /**
   * auto splice file directory, It only takes effect at the first level of subdirectories
   * @default /
   * @example virtual:demo-loader/button  + childrenResolvePath: 'src' => .../button/src/
   * @example virtual:demo-loader/button  + childrenResolvePath: 'demo' => .../button/demo/
   *
   * |- loader path@root(options.paths)
   *  |- button
   *   |- src (childrenResolvePath effect)
   *    |- index.html
   *    |- other
   *      |- src (not effect)
   */
  resolveChildrenBase?: string | ((id: string) => string)
  /**
   * @default true
   * @example virtual:demo-loader/button/basic + (childrenResolvePath: 'src', enableResolveLongChildren: true)
   *  => ...button/src/basic
   */
  enableResolveLongChildren?: boolean
  /**
   * @default false
   * If true, the file content will be imported dynamically, and matched files are by default lazy-loaded via dynamic import and will be split into separate chunks during build
   */
  dynamicImport?: boolean
}