Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with webpack #44

Closed
BarryThePenguin opened this issue Feb 8, 2016 · 5 comments
Closed

Usage with webpack #44

BarryThePenguin opened this issue Feb 8, 2016 · 5 comments

Comments

@BarryThePenguin
Copy link

I've had success in the past using this module with webpack. I'm not sure when or which version the change occurred, but this is no longer the case.

I've setup a gist with the bare minimum code showing what I've been doing.

Output from webpack

WARNING in ./~/markdown-toc/lib/utils.js
Critical dependencies:
7:34-41 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/markdown-toc/lib/utils.js 7:34-41

Output from browser

bundle.js:10939 Uncaught Error: Cannot find module 'remarkable'.

I have tried process.env.UNLAZY = true; as suggested in lazy-loader
This results in a failure to resolve minimist

I have tried doowb/unlazy-loader
Though as I'm using babel on my own source files, I can't use unlazy-loader without running babel across all my node_modules which takes a long time.

I have tried using unlazy in my import statement

import toc from '!unlazy!markdowntoc';

This results in just markdown-toc/index.js being resolved with unlazy.

I understand there are a lot of parties involved here, so I thought I'd start here and hopefully involve others as the need arises.

These were the two related issues I found
jonschlinkert/lazy-cache#3
webpack/webpack#1763

@doowb
Copy link
Collaborator

doowb commented Feb 8, 2016

Adding these sections to the webpack.config.js work fine for me:

  // this is required because `gray-matter` uses the `fs` module for some things
  node: {
    fs: "empty"
  },

As the last loader:

, {
      test: /\.js$/,
      loaders: ['unlazy']
    }

This will work because you've already transformed your scripts through babel, now the unlazy loader will work on anything other javascript that's required through a require statement. No need to transform the entire node_modules with babel. Also, unlazy-loader will return quickly when it detects that the file doesn't need to be transformed, so this is a lot faster than the babel transforms.

@BarryThePenguin
Copy link
Author

Ah! Thank you @doowb!

In addition to the last loader, I added an include regex so unlazy is only applied to the markdown-doc directory.

{
    test: /\.js$/,
    loaders: ['unlazy'],
    include: /node_modules\/markdown-toc/
}

It didn't help that I have two sets of loaders, dev and prod, and unlazy was only being used by prod. But oh well...

Thanks again!

@devuxer
Copy link

devuxer commented Feb 12, 2019

For those using Create-React-App, this is not really a solution (since we don't have any direct way to modify webpack.config.js).

Is there any way this could be fixed properly (without having to touch webpack), and if yes, would you consider re-opening this issue?

@mdddj
Copy link

mdddj commented Feb 7, 2020

#44 (comment)
我遇到了这个问题,请问怎么解决的?

@kurikomoe
Copy link

#44 (comment)
我遇到了这个问题,请问怎么解决的?

maybe you can use https://www.npmjs.com/package/markdown-toc-unlazy as alternative

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants