mariusschulz / gulp-iife Goto Github PK
View Code? Open in Web Editor NEWA Gulp plugin for wrapping JavaScript code in IIFEs.
Home Page: https://www.npmjs.com/package/gulp-iife
License: MIT License
A Gulp plugin for wrapping JavaScript code in IIFEs.
Home Page: https://www.npmjs.com/package/gulp-iife
License: MIT License
Hi,
I am running Node 5.0.0 and NPM 3.3.6.
$ gulp
module.js:339
throw err;
^
Error: Cannot find module 'gulp-iife'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/Users/ilovecoffe/test/gulpfile.js:9:13)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
I tried to use the args option. It just adds (function(){ ...})(arg1, arg2);
I expected (function(arg1, arg2){ ...})(arg1, arg2);
.
The second issue is that I have to declare global variables first ( to use window, document or undefined I have to write the following first var window = window
)m before I can use them in the args array
It would be awesome if this plugin supported sourcemaps (a la https://github.com/floridoo/gulp-sourcemaps). I've tried to use them with an intermediary iife pipe operation but then my breakpoints seem to be thrown off in the browser's developer tools.
Here is some documentation: https://github.com/floridoo/gulp-sourcemaps#plugin-developers-only-how-to-add-source-map-support-to-plugins
Is there any way to programmatically detect that there is already an IIFE? Our codebase already uses IIFEs, but I am thinking about using gulp-iife instead. I am worried about the performance implications of using 2 IIFEs, though I haven't done any performance tests. It's a big codebase, so I have to think there would be at least some performance loss, though this may be dwarfed by our use of angular, among other things.
One of our applications already uses gulp-iife, and it seems to work fine. The only issue is that we do not concatenate with gulp-iife in development, meaning things like an accidental global this
causes problems in production but not development, but that is on us. Anyway, great job!
If there is no (easy) way to programmatically detect that there is an IIFE, or if you have to use acorn
or something like that, please ignore and close this issue. If there is a way, could you look into supporting this? I would be fine with it being an optional option.
I'm using a gulp task to combine and minify js files.
Some of those files belong to vendor libraries. Others are my own code.
I only want to add the iife to my won code. How can I do this without having to generate two temporal files that I combine later on?
// guards against the function becoming an argument when two files with IIFEs are concatenated
;(function() {
...
})();
Hi Marius, I'd like to suggest you one new feature for your plugin. Sometimes it is needed to have one or more names (variables or functions) from the original code to be exported as globals. For example:
var a = 'some private stuff';
var b = 'some other private stuff';
// this is my object I would like to be globally accessible after wrapping into IIFE
function MyObject(params)
{
// here I'm using a, b and other private members
...
}
I would want this code after processing:
(function(context, globals) {
var a = 'some private stuff';
var b = 'some other private stuff';
// this is my object I would like to be globally accessible after wrapping into IIFE
function MyObject(params)
{
// here I'm using a, b and other private members
...
}
// section to export global names
for(var i = 0; i < globals.length; i++)
context[globals[i]] = eval(globals[i]);
})(window, ['MyObject']);
where context and globals are both specified in plugin's config. context is global namespace usually window, globals is just an array of existing var/function names we want to be accessible at global level. eval is used to specify var/function by string name inside IIFE (it seems like this is the only way to access local name inside IIFE).
What do you think?
Hey! How are you?
I came to to try to contribute into updating lodash version and I checked out you already did it.
Would you mind to publish this new version?
I runned the tests and everything sound ok. Is something needed? I Please, let me know If I can help somehow.
Thanks for your work.
Hi,
Directory Structure:
app/
|__images/
|__scripts/
|__adapters/
|__adapter_one.js
|__adapter_two.js
|__ ...
|__models/
|__model_one.js
|__model_two.js
|__ ...
|__ ...
|__app.js
Gulp Task:
gulp.task('iife', function() {
return gulp.src('app/scripts/**/*')
.pipe(iife({ useStrict: false }))
.pipe(gulp.dest('app/test/'));
});
Running above task gives you following error:
$ gulp iife
[18:01:55] Using gulpfile /Users/ilovecoffee/app/gulpfile.js
[18:01:55] Starting 'iife'...
[18:01:55] 'iife' errored after 96 ms
[18:01:55] Error: EEXIST: file already exists, mkdir '/Users/ilovecoffee/app/test/adapters'
at Error (native)
What is strange is that iife
creates test
folder with adapter
file. The content of this adapter
file is:
// adapter.js
;(function() {
null
}());
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.