Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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

install

npm i quokka-plugin-subdir

Downloadsweekly downloads

1

version

0.1.0

license

MIT

repository

githubgithub

last publish

collaborators

  • avatar