thlorenz / exposify Goto Github PK
View Code? Open in Web Editor NEWbrowserify transform that exposes globals added via a script tag as modules so they can be required.
License: MIT License
browserify transform that exposes globals added via a script tag as modules so they can be required.
License: MIT License
First of all, I'm not actually sure if this is an issue - it might be me who's misunderstanding how I'm supposed to use this - if so, sorry about that, and feel free to close the issue immediately, but I couldn't find a better way to contact you.
So, as the title says, I can't seem to get exposify to work at all. I'm trying to integrate it into a gulp build system. I've managed to reduce the problem to a very simple test case, and put it online: https://github.com/levacic/exposify-test
My use case is very basic, and according to the documentation, it's exactly what this library should be used for - I'm including jQuery via a <script>
tag, but I want to be able to require
it in my application code. I actually ran into these problems while trying to integrate browserify-shim, but upon failure, I figured I'd try just exposify, since it seems to be much simpler, and possibly easier to debug. I thought I could make this work first, and upgrade to browserify-shim afterwards, but I'm stuck.
Running "gulp" from the command line throws this error:
$ gulp
[gulp] Using gulpfile /home/levacic/www/exposify-test/gulpfile.js
[gulp] Starting 'default'...
[gulp] Finished 'default' after 3.6 ms
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: module "jquery" not found from "/home/levacic/www/exposify-test/source/app.js"
at notFound (/home/levacic/www/exposify-test/node_modules/browserify/index.js:775:15)
at /home/levacic/www/exposify-test/node_modules/browserify/index.js:726:23
at /home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/index.js:183:24
at /home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:44:14
at process (/home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:110:43)
at /home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:119:21
at load (/home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:54:43)
at /home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:22
at /home/levacic/www/exposify-test/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:16:47
at Object.oncomplete (fs.js:107:15)
I have absolutely no idea what's the problem - I think I've done everything according to the documentation. When I tried the same thing with browserify-shim, I kept getting the same errors, even when just running browserify directly from the command line - so it shouldn't have anything to do with gulp.
Can you share some advice on what I'm doing wrong?
Thanks!
exposify seems to not work with files that have JSX
For example, Im writing some jquery plugin in cjs style, then I bundling it:
(function(factory) {
if (isNode) { ... factory(jQuery) } else if (isAMD) {... factory(jQuery) } else {... factory(jQuery) }
})(function(jQuery){
return require('my_plugin');
});
Source of 'my_plugin' module:
module.exports = require("jquery");
And this code exposed after bundle like:
bundler.transform('exposify', {
expose: {
jquery: "jQuery"
}
});
module.exports = (window.jQuery);
But I just want to use it like:
module.exports = (jQuery);
because of umd wrapper above.
Thanks! =)
I need @bendrucker 's patch...
In the ReadMe for exposify it says:
Or use it via browserify-shim which allows you to provide exposify config inside your package.json among other features.
I'm really confused where in my package.json I would set exposify.config using browserify-shim. Can you provide an example or show a simple setup in the main page Readme?
Is it in the browserify transform option:
"browserify": {
"transform": [
"browserify-shim",
"exposify" <-- HERE
]
},
Or perhaps in the browserify-shim config itself:
"browserify-shim": {
"jquery": "global:jQuery",
"angular": {
"exports": "angular",
"depends": [
"jquery:jQuery"
]
},
"hammer": "HammerJS",
"kendo": {
"depends": [
"jquery:jQuery"
]
}
},
Thanks in advance!
Version 1.0.3 has a fix: bendrucker/replace-requires#1
This will make it possible to replace require('react/addons')
using this transform.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.