quokka-plugin-subdir

0.1.0 • Public • Published

quokka-plugin-subdir

Small quokka plugin for resolving node_module imports from subdirectories

But why?

I am using quokka mostly in "scratch" mode to check/test small pieces of code that uses project node_modules. In general it's not a problem until you have some kind of monorepo, so there is a lot of subdirectories with their own modules, even tho it's not a problem until you are doing this in scratch mode.

Scratch mode will relate on repo root directory, trying to load modules from repo/node_modules, in this case the only option is to write full relative path.

Usage

Add plugin to quokka config:

{
  "plugins": ["quokka-plugin-subdir"],
}

can be used in two ways, let's say you have monorepo with 2 projects in it:

my-monorepo-project
├── client
├── server

First way is adding "subdir" into config:

{
  "quokka": {
    "plugins": ["quokka-plugin-subdir"],
    "subdir": "client"
  }
}

(can be added directly in quokka file, see details)

With above configuration:

const _ = require('lodash')

is equal to:

const _ = require('./my-monorepo-project/client/node_modules/lodash')

Second way is adding tilda symbol before import:

const koa = require('~server/koa')

is equal to:

const _ = require('./my-monorepo-project/server/node_modules/koa')

By default imports prepended with tilda will have advantage over subdir config

Install

You can install it as dev dependency for your package:

Yarn

yarn add --save --dev quokka-plugin-subdir

NPM

npm install --save-dev quokka-plugin-subdir

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    21
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    21

Package Sidebar

Install

npm i quokka-plugin-subdir

Weekly Downloads

21

Version

0.1.0

License

MIT

Unpacked Size

4.57 kB

Total Files

5

Last publish

Collaborators

  • nodman