Small quokka plugin for resolving node_module imports from subdirectories
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.
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
You can install it as dev dependency for your package:
yarn add --save --dev quokka-plugin-subdir
npm install --save-dev quokka-plugin-subdir