-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Support dynamic require #9
Comments
This is pretty tricky but might be possible in some cases where |
Another usecase (from cheerio): var api = ['attributes', 'traversing', 'manipulation'];
api.forEach(function(mod) {
_.extend(Cheerio.prototype, require('./api/' + mod));
}); Probably more of a browsersify core issue, but it does seem slightly related. |
The sledge hammer approach taken by nodejitsu/require-analyzer is to first check if all While this would certainly work for browserify, it might complicate the development process, as the compilation thread in the background might run into an infinite loop and block the system. browserify should at least add support for statically resolving variables, plus some of the array extras. Especially let [fs, path] = ["fs", "path"].map(require) |
I have this use case [ 'a.js', 'b.js' ].forEach(js => {
injectJS(fs.readFileSync(js));
}); |
I had this issue too, but as said before, couldn't achieve this with brfs. What I did was a simply fetch request. Would it be possible to replace fs.readFile('posts/' + post + '.md', function (err, content) {
// process file
}) with fetch('posts/' + post + '.md')
.then(response => response.text())
.then(content => {
// process file
}) So it would dynamically load files with ajax? |
@YerkoPalma even better now: var content = (await fetch(`posts/${post}.md`)).text() |
@dy fetch()'s return value doesn't have a .text() method, so with var resp = await fetch(`posts/${post}.md`)
var content = await resp.text() |
Many modules uses
require
to dynamically load JSON files.Example:
The text was updated successfully, but these errors were encountered: