question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configurable module resolvers

See original GitHub issue

When there’s custom resolver logic being used by Webpack in the project Docz is unable to find them. For example, when using something like directory-named-webpack-plugin Docz seems unable to resolve modules.

For example, given the following resolve setup in webpack.config.js

resolve: {
  modules: [path.resolve('./src'), path.resolve('./node_modules')],
  plugins: [
    // Then when require("component/foo") and the path "component/foo" is
    // resolved to a directory, Webpack will try to look for
    // component/foo/foo.js as the entry (given default options).
    new DirectoryNamedWebpackPlugin({
      include: [path.resolve('./src')],
    }),
  ],
},

components/TextInput/TextInput.js

import Button from 'components/Button';

export default class TextInput extends Component {}

components/TextInput/TextInput.mdx

---
name: TextInput
---

import { Playground, PropsTable } from 'docz'
import TextInput from './TextInput.js'

# TextInput

<PropsTable of={TextInput} />

## Basic usage

<Playground>
  <TextInput></TextInput>
</Playground>

Results in

This dependency was not found:

  • components/Button in ./src/components/TextInput/TextInput.js

Similarly if i were to change the import of TextInput.js in the mdx file to

import { Playground, PropsTable } from 'docz'
import TextInput from 'components/TextInput.js'

This dependency was not found:

  • components/TextInput.js in ./src/components/TextInput/TextInput.mdx

It’d be great if we could configure the webpack resolver options (and therefore be able to import the ones from the project’s webpack.config.js file).

Jest has a similar feature whereby you can set the module resolver to a module/function. This module jest-webpack-resolver grabs the config from webpack and plugs it into jest. Perhaps this could be used for ideas?

Apologies if I’m missing something and there’s already a facility by which do do something like this?

Cheers

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
pedronauckcommented, Jan 21, 2019

Use onCreateWebpackChain to create your alias, it’s more safety:

export default {
  onCreateWebpackChain: config => {
    config.resolve.alias.set('foo', 'bar')
  }
}
0reactions
adeelibrcommented, Feb 10, 2019

Also I am using rollup, for my library melting-pot https://github.com/withvoid/melting-pot! So the below change was the option for me for using alias in docz site https://melting-pot.netlify.com/

// .babelrc
(...)
"plugins": [
    ["module-resolver", {
        "root": ["./src"],
        "alias": {
            "app": "./src/app"
        }
    }]
],
(...)

Reference https://github.com/pedronauck/docz-plugin-css/issues/1#issuecomment-425502093

P.S: Thank you for such an amazing tool.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers - webpack
Resolvers are created using the enhanced-resolve package. The Resolver class extends the tapable class and uses tapable to provide a few hooks.
Read more >
tleunen/babel-plugin-module-resolver - GitHub
This plugin allows you to add new "root" directories that contain your modules. It also allows you to setup a custom alias for...
Read more >
babel-plugin-config-module-resolver - npm
A babel plugin that resolves modules using the tsconfig.json or jsconfig.json configuration. Latest version: 1.0.2, last published: 3 years ...
Read more >
Resolver - Parcel
Resolver plugins are responsible for turning a dependency specifier into a full file path that will be processed by transformers. Resolvers run in...
Read more >
Module Resolution or Import Alias: The Final Guide - Raul Melo
Tired to have weird imports? It's time to learn how can you enable aliases to your imports and let code more organized.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found