Comments (5)
Sounds like this just needs to be updated to the latest lazy-cache format.
Is lazy-cache really necessary?
Is webpack necessary? You could hand-code all of that yourself, but that's silly. What you're really asking is: "Is it really necessary to try to get the best possible performance from your modules?". To which my answer is, "No, but I'll try my hardest, and I'll base my decisions on facts, data and experience."
I don't think it's a good idea to wrap require in any way, ever.
If wrapping require
bothers you, then you probably shouldn't look at what browserify and webpack do to your code.
it's not really a solution, but a hack.
Isn't that semantics? Without the hack neither webpack nor browserify can find lazy-requires, with the hack ~~~they~~~ browserify can.
This hack has turned out to be a pretty good solution. Instead of thinking that lazy-evaluation is a bad solution because the tools you use fail when it's used, perhaps you should be looking for ways to solve that problem. I do, because I know how big the benefits are.
lazy-cache has had something like 8m downloads in the past 4 months, with two issues - including this one, both related to webpack. Materially, both issues were on projects that use the old-style lazy-cache, and we've had zero actual issues on lazy-cache itself. browserify does not have this issue.
IMO this is something that can be solved in a build step, or with a webpack plugin.
from markdown-toc.
I'm okay with Browserify / Webpack doing crazy things to my code, because that's expected of them. They're pretty much transpilers, making require
/ import
work in browsers.
This, however, is a regular library. Lazy loading does make sense here, but, in the end, on the client-side, where it matters the most, gray-matter
still ends up being in the same bundle as markdown-toc
(with Browserify; correct me if I'm wrong).
Webpack has its own mechanism for on-demand loading - require.ensure
- but it doesn't work anywhere else (well, it did, but seems like nobody cared enough about server-side lazy-loading to maintain it; can be shimmed, with the benefits gone). lazy-cache
is admittedly more convenient, but, on top of breaking the convention of having imported modules as variables, it also works only in Node, and nowhere else (it has no benefits in Browserify).
You're saying that this issue should be resolved in Webpack, but why should lazy-cache
be preferred over the several-years-old require.ensure
?
Sorry for challenging your design choices like this, I don't mind being proven wrong.
from markdown-toc.
You're saying that this issue should be resolved in Webpack
Well, I'm saying it's "meet in the middle". We can use the hack that got this working for browserify, and we could create a plugin for webpack to convert the lazy-requires to standard requires. I don't know webpack, it seems like it shouldn't be too difficult.
I get your point about how the benefits of lazy-evaluation are lost in non-node usage, but this is, after all, a node.js package. But again, I'd like to find a solution that allows us to take advantage of lazy-caching for node.js, but also make it work with browserify and webpack. I think the community in general would/should see great benefit in that
from markdown-toc.
Out of curiosity, what was the reason for not doing something like this?
if (file) {
return require('gray-matter').stringify(res, file.data);
}
Lazy-loading + caching in Node, while working out of the box in Browserify / Webpack / some other lib we could be unaware of.
Just in case, I'm using this library as a client-side patch for some missing backend functionality, which isn't going into a public release, so there's no urgent need for a fix.
from markdown-toc.
@jeremejevs try using the unlazy loader in your webpack build.
from markdown-toc.
Related Issues (20)
- Ignore existing heading anchor
- --no-firsth1 option causes "undefined" words to appear in the toc HOT 3
- wrong output and slug generated (using GFM as reference) when title contains a link
- inline code is stripped, even with --no-stripHeadingTags
- Invalid links
- Error: Cannot statically analyse 'require(…, …)' in line 16 HOT 4
- -- the maxdepth parameter does not work on my Mac notebook
- Proposal: Add more detailed usage for toc.insert
- Generated ToC includes commented headers
- Unable to report version
- Extra newlines added when file has horizontal lines
- How do you add the anchors to the headings?
- Not working with esbuild/vite HOT 1
- cli option no-firsth1 naming is misleading
- Where is the generated toc HOT 1
- error in create-react-app
- Image for sponsorships
- want to help maintain markdown-toc? HOT 2
- Document with literal `---` or single horizontal rule at top is mangled
- Strange OpenGL output in place of toc? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-toc.