calvinmetcalf / derequire Goto Github PK
View Code? Open in Web Editor NEWremove require statements without breaking scope
License: MIT License
remove require statements without breaking scope
License: MIT License
Some require
function calling which calls external libraries are desired to keep that function name because we cannot rebundle derequired libraries using browserify. Could you add the exclude option for rebundling?
derequire(code, [
{
exclude: ['another'], // `require('another')` -> `require('another')`
from: 'require', // `require('./index.js')` -> `_dereq_('./index.js')`
to: '_dereq_'
}
]);
For browserify v5 I'm dropping derequire for standalone for performance reasons but would like to present a concise alternative for command-line usage. A dequire
command would be very good for this, especially if it could just read from stdin and write to stdout. If you agree I can send a pull request with an implementation.
Hi Calvin, The use case I'm currently facing is 3 browserify applications sharing a single resource with some overlap in require's between the resource and the applications. Is this a typical scenario where you'd use derequire, maybe with stubs?
Thanks,
Thad
From Log:
158 error Error: No compatible version found: esprima-fb@'^3001.1.0-dev-harmony-fb'
158 error Valid install targets:
158 error ["1001.1001.1000-dev-harmony-fb","1001.1001.1001-dev-harmony-fb","1001.1001.2000-dev-harmony-fb","2001.1001.2000-dev-harmony-fb","2001.1001.0-dev-harmony-fb","3001.1.0-dev-harmony-fb"]
158 error at installTargetsError (C:\Program Files\nodejs\node_modules\npm\lib\cache.js:719:10)
158 error at C:\Program Files\nodejs\node_modules\npm\lib\cache.js:638:10
158 error at saved (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\get.js:142:7)
158 error at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:133:7
158 error at Object.oncomplete (fs.js:107:15)
159 error If you need help, you may report this log at:
159 error http://github.com/isaacs/npm/issues
159 error or email it to:
159 error [email protected]
160 error System Windows_NT 6.1.7601
161 error command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "-g" "derequire"
162 error cwd D:\Projects
163 error node -v v0.10.15
164 error npm -v 1.3.5
165 verbose exit [ 1, true ]
Can the plugin be documented?
Hello, @calvinmetcalf
So, upon trying to bundle a React library recently using browserify & derequire, I ran into a problem.
If I bundle React with the module then when it's installed you end up with 2 versions of React running in your application, which causes a host of problems. Alternatively you can exclude modules from your bundle, but then after derequiring, the libraries will not get required when building your application.
My suggestion is that another option is added (with the same syntax as browserify's CLI) so that certain requires can be excluded from derequiring e.g.
browserify --exclude react input.js | derequire --exclude react > output.js
Note: browserify's exclude is also aliased to -u
. https://github.com/substack/node-browserify#usage
This the above command would not bundle React with the library, but would also not rename the requires. So the following:
var React = require('react');
var otherLib = require('other-lib');
Would compile to:
var React = require('react');
var otherLib = _dereq_('other-lib');
I started having a play around with this here: JakeSidSmith#1
I'm not certain that this approach will even solve my problem, but haven't got it to a suitable point to test it yet.
I'm using a custom walker for the AST, and having not worked with escope before was a little confused by all the scope stuff. Currently all tests are passing (plus my new addition) except for a couple of the larger ones, in which certain requires are not supposed to be replaced. I believe this is because they are "tainted"? Though I'm not sure of the meaning.
Let me know what your thoughts are, and if you could explain what "tainted" is, or why those couple of tests have some requires that are not modified, that'd be really helpful. :)
Looks like doesn't work since ES2017. Can support the latest syntax?
If this were available as a transform, it could be used with watchify. Any interest?
Could you please create a LICENSE file with your copyright information and the text of the MIT license? The MIT license requires that the text of the license accompany the source code.
see thlorenz@be968c5
var jQuery;
if (!jQuery && typeof require === 'function') {
jQuery = require('jquery');
}
not properly replaced.
Note: In order to avoid quite a few headaches the token you're changing from and the token you're changing to need to be the same length.
What are those issues?
Let's say we don't have a good js knowledge ;)
Thanks
via os-local https://github.com/sindresorhus/os-locale/blob/master/package.json#L2
just by requiring this as a lib, a user is required to have a working compiler toolchain, and portability between various nodes becomes dubious.
Hey there,
I'm currently using gulp-derequire@latest on node 6.9.1, npm 3.10.9. The latest version of derequire is using a very old version of escope, which means you get this error:
node_modules/estraverse/estraverse.js:517
throw new Error('Unknown node type ' + nodeType + '.');
^
Error: Unknown node type AssignmentPattern.
When you use derequire. This appears to be a solved issue in the underlying libraries, with estraverse >4.2.0 being the minimum version for the fix.
Is there any chance of this being updated to resolve this bug down the bottom of the dependency chain?
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.