-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to provide generated content as module ? #1436
Comments
with custom resolve function : var generatedModules = {
'a': textContent,
};
browserify({
fileCache: _.clone(generatedModules),
resolve: function (id, parent, cb) {
var filename = null;
if (generatedModules[id]) {
filename = id;
}
_.defer(_.partial(cb, null, filename));
},
}) |
@Cactusbone Perhaps what's discussed here will give you at least a temporary solution: #1440. As noted there though, the plugin is implemented using the undocumented ability to set module-deps |
@Cactusbone Even if you combine it with the |
@jmm Yeah, I'll try it again and report back :) |
@jmm humm looks like you're right ! I must have found fileCache option long after trying .resolver I like this solution better since I don't have to depend on a custom fork. even if i'm using undocumented code. final code : var generatedModules = {
'a': textContent,
};
var bundle = browserify({
fileCache: _.clone(generatedModules),
});
bundle.plugin(generateRequires, {generated: generatedModules});
function generateRequires(b, opts) {
var generatedBundles = opts.generated || {};
var deps = b.pipeline.get('deps');
deps = deps.get(0);
var defaultResolver = deps.resolver;
deps.resolver = function (id, opts, cb) {
if (generatedBundles[id]) {
cb(null, id);
} else {
return defaultResolver(id, opts, cb);
}
};
} |
@Cactusbone Thanks for the feedback. Just be aware of the usual caution that it's subject to break at any time. You may also want to handle the |
I need to be able to provide generated content as dependencies to bundles
during build (using api) I know what the generated content will be, but there's no file containing it. it's only in memory. so i want to provide it to the bundle requiring it.
I can indeed do
but this means my bundle ends up with 'a' even when it's not required.
any tips ?
The text was updated successfully, but these errors were encountered: