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.

Stream Non-Entry Files

See original GitHub issue

I’m trying to also stream files that the entry file requires is this possible? I have been looking for a while and haven’t found innate to browserify or a plugin.

Simplified Example:

const str = require('string-to-stream');
const browserify = require('browserify');

const entry = "const func = require('./func.js')";
const func = "module.exports = function() {return 'func'}";

browserify(str(entry), {basedir: __dirname})
  // somehow map './func.js' to func string

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mattdeslcommented, Mar 2, 2018

I am doing some similar things in my tools, generating source on the fly in response to certain require statements. If you are OK with requiring a module name like 'foo-bar' rather than relative path, you can do this:

const fromStr = require('from2-string');
const browserify = require('browserify');

const entry = `module.exports = require('foo-bar');`;
const other = `module.exports = "foobar";`;

const b = browserify(fromStr(entry), {
  basedir: __dirname
});

b.exclude('foo-bar');
b.require(fromStr(other), {
  // Make up a file name for the stream
  // If the file name is within node_modules, then
  // it will get skipped by non-global transforms
  file: 'foo-bar.js',
  expose: 'foo-bar'
});

b.bundle((err, src) => {
  if (err) throw err;
  console.log(src.toString());
});

If you need relative file names like ./foo-bar.js, you may have to dive into plugins, potentially doing something like altering the .source property as rows come through the pipeline, if the id matches the file you are trying to modify.

NOTE: These things can cause issues with watchify since there is no file on disk to invalidate the cache; so you can’t really have a dynamic stream that changes over the course of development. At some point I hope watchify or browserify API will introduce some method of invalidating a resource by file ID or something, to fix this pitfall.

0reactions
BebeSparkelSparkelcommented, Mar 3, 2018

Repo for plugin require_stringify

Read more comments on GitHub >

github_iconTop Results From Across the Web

File Streams (Local File Systems) - Win32 apps - Microsoft Learn
A stream is a sequence of bytes. In the NTFS file system, streams contain the data that is written to a file, and...
Read more >
TypeStrong/tsify: Browserify plugin for compiling TypeScript
2.0.7 - Tracked files for filtered stream and module-name 'rows'. ... 0.11.13 - Fixed bug introduced in last change where non-entry point files...
Read more >
yarb - UNPKG
This allows passing in existing buffers/streams by just wrapping them in vinyl objects beforehand. ... 40, Adds non-entry files to be included in...
Read more >
ELD List - ELD - Electronic Logging Devices
Transfer via Bluetooth - this option enables the user to transfer files through Bluetooth. The ELD prompts for an output file comment which...
Read more >
Confined Space Post-test answer key
Non entry rescue c. Entry rescue d. All of the above. 4. a permit-required confined space has one or more of these characteristics....
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