Package Exports
- quokka-plugin-subdir
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (quokka-plugin-subdir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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