-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Simplify prototypes for faster execution and simplify bootstrap.native.js packaging #71
Comments
Have you ever looked into https://github.com/substack/node-browserify? This allows you to write your files in the commonjs module format. Then you can run browserify to bundle all of your files in a UMD wrapper. |
No I haven't, I am totally new to this stuff and I don't afford the time for. |
How were you considering packing |
Perhaps this would shed some light. |
If you can join me on skype, I can totally provide info on what is to be done. |
@thednp I understand what you're trying to do. A few notes:
Gotta go, discuss more later. |
That file is to be used by users with |
OK, I understand what you're saying, however:
Are you sure you really want to copy code back and forth whenever you change something? |
When it comes to npm/requirejs/commonjs I'm never sure, that's why I ask for experienced users on what's best to do so that everybody is happy. If there's a way to achieve exactly what I've done with the current Generally I need help with the following things:
|
That is easily possible, I'll try to submit a PR soon (might be next week). |
If you want both the bundle and the lib files exactly the same as they are now, I don't know of a way to do it.
I agree. However, the way you are doing it now, CommonJS users will not get any of those benefits. A brief overview of the CommonJS module system:
|
Hey what about a wrapper for the bundle I cooked with the current Users can do CommonJS/RequireJS for the bundle OR build custom bundles themselves with the files from |
That won't work for a few reasons:
For now, if you're fine with the copy-paste hassle, lets just leave things as they are. I'll try to automate the minification. |
@thednp Any reason to keep this open? |
@RyanZim I still need some opinions, as v1.0.4 is already doing what I explained above. Nobody seems to care/want to get involved. Perhaps users' silence is a sign of approval (because my idea was brilliant in the first place)? I am thinking: what if we create a different repository only for npm stuff and the current master have it do all things outside npm and UMD? What do you think? |
I don't use UMD so for me that would be a 💯 The only thing I don't really know is the effort to achieve that and if that worth it |
👎 Keeping bootstrap-native.js and lib/ in sync is enough trouble. Trying to keep two repos in sync is double trouble. |
Good now, we have some feedback. |
The other crazy idea I just though of: Is making separate files for each module really needed? Does anyone use the files in lib/ directly? If not, I could write a single UMD wrapper for the whole library and we could edit all the source code in one file. |
That's what I am also unsure, I was thinking having them ( For instance I don't use carousel, affix, scrollspy and button, so a custom build is a bliss, because an entire lib would overkill the purpose. |
Perhaps others think differently, but bootstrap + jQuery slim is about 59.8KB. With that size, one could see making a custom build. bootstrap.native is only 33KB, so this is less important. However, if you want to keep the separate files, I'm thinking about the possibility of developing a fairly complex build script that would reduce boilerplate UMD wrappers for both npm and |
The later. |
OK, let me think over the best way to do it; might be a couple of days. |
You can write a bullet listed plan that we can discuss, things come from all directions I am sure of that. |
OK, here is a quick proposal for bundling:
With this system, we would no longer need the Perhaps we could consider adding a Please don't try to start implementing any of these changes; I'll implement them all at one time when this proposal is approved. |
I like what I see in the code area but I will think about the rest. |
Thinking about this a little more, this layout is asking for variable naming conflicts. Revision to proposal: Each module runs inside an IIFE, but declares its main variable into whatever scope it is run in. Example:
This keeps the data api variables contained in the IIFE. |
I don't like that kind of wrapping, perhaps that wrapping could be done inside the |
@thednp The issue with my initial proposal is that in the bundle, all the data apis will be running in the same scope (resulting in variable naming collisions). You could do the wrapping differently than above, just so the data api's variables aren't all running in the same scope. Another way to write modules (I sort of prefer this form):
D3 uses RollupJS; I haven't tried it, but I plan to on an upcoming project. RollupJS is actually a module bundler for the ES15/ES6 module format (which hasn't been natively implemented in any browser or runtime yet). |
Fascinating stuff. |
So what are your thoughts on bundling here? |
My mind is full of noise, why don't you do a fork we can work on together and when we have all things working perfect we can pull it to our master here. |
SGTM, won't get to work much on it until Monday. My fork is https://github.com/RyanZim/bootstrap.native. I will be working on a branch named Warning: I rebase and force-push quite often. Beware of this if you clone my fork! |
I have a question regarding UMD and performance. You see I'm developing the KUTE.js and I am thinking about a way to define a custom global scope outside UMD wrapper, something to work fast with native functions. Have a look at this:
What do you think? Is this doable/legal/working/possible? I am all ears!! |
A few problems:
Not sure why the scope needs to be global, just do |
You mean here? (function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory); // AMD. Register as an anonymous module.
} else if (typeof exports == 'object') {
module.exports = factory(); // Node, not strict CommonJS
} else {
// Browser globals
window.KUTE = window.KUTE || factory();
var scope = {}// HERE??????????????
}
}( function () {
"use strict";
return K;
})) |
|
You are right about that. So I am going to export stuff to global |
Look at this:
You can read properties from The only place you should export stuff to global is in the UMD wrapper itself: BTW, |
Thank you. I would love to see you around the project with some ideas on how to improve it. |
Sorry, I don't use many animations on my sites, and most of them are simple enough to do in CSS. |
It's not about you using it or not. It's about contributing to the community, and you would only be required with npm/UMD stuff, but I think I managed, I will commit a new version of KUTE.js as soon as I finish all tests. |
@thednp Had extra time today and got to work on it. Check out https://github.com/RyanZim/bootstrap.native/tree/bundle. 🎉 Build script usage:
You can run
Warning: I used some ES6 features in Let me know what you think. |
That looks solid, I will dig into that as soon as I wake up tomorrow. |
Before I go: how would you connect utilities to each lib? Each script needs specific stuff, so no need to use them all if only 2-3 needed? I have an idea but I don't know how it's gonna be implemented with this npm stuff. |
@RyanZim It looks good. You can simplify a lot of the places where you return a boolean by just returning the condition. For example Beforevar allModules = fs.readdirSync('lib/').filter(function (item) {
if (/-native\.js$/.test(item)) {
// Is module:
return true;
} else {
// Ignore:
return false;
}
}); Aftervar allModules = fs.readdirSync('lib/').filter(item => /-native\.js$/.test(item)); |
I think |
@thednp Passing options directly to Regarding utilities, the minified utils are only around 800 bytes! I think should worry about other optimizations with greater returns. @styfle Thanks for the tip! Will fix. |
I have a new working code for all modules to work a bit faster, it's a bit more simple and I am also considering packing the
bootstrap.native.js
file different and not just a concatenation of the modules.The reason is simple: why write same utility function over and over (
addClass
orisIE
) as well as using module definition for each module when in fact an user gets the all in one package to use it on his web pages, without the need to do require, import, etc.I really need to know what people think about it.
The text was updated successfully, but these errors were encountered: