-
-
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
Can I import a small part of mathjs to reduce its size? #1199
Comments
Fraction.js is indeed just a small, independent libary of mathjs. If you only need fractions, you may just use the fraction.js library instead of mathjs: https://github.com/infusion/Fraction.js/ You can indeed create a custom bundle of mathjs containing just the parts you need (options are still limited though we're working on that, see #71): http://mathjs.org/docs/custom_bundling.html |
Actually, I used Fraction.js in the beginning, but it didn't work perfectly. Our instructor just ignored the problem. One of my classmates mentioned about mathjs, so I tried and it solved my problem, and I'm happy with it. The link of #71 looks different than my code, I'm not sure how to adopt those... I did Can I use This is my first project that is combining ES6, webpack, npm, and Babel together, I'm not familiar with those. Please let me know how to import a single part of mathjs such like fraction. Thank you very much!!! |
#71 is a proposal which isn't yet implemented. As for the custom bundling, please check out the docs and examples on this subject: docs: http://mathjs.org/docs/custom_bundling.html |
I used the following from http://mathjs.org/docs/getting_started.html. But I can't figure out how to use "ES6 import" one part of mathjs such as "fraction". To josdejong, I'm not a programmer, and I just started learning JS a month ago, so sorry I don't have much knowledge to understand everything. |
I would be very appreciated if anyone can show me how to use |
Please follow my advice above. Read the docs. The example I linked to is exactly what you ask for, thought you could rewrite the Unless you just need fraction.js itself which would be easier, I guess you need additional functionality which is not available in fraction.js? |
Copy from the link: I tried to use ES6 import...but nothing worked:
I guess I need to learn more about ES6 so that I will be able to figure out how to ES6 import correctly. fraction.js caused some unknown errors, and I couldn't get the result as I need. So I switch to mathjs. Anyway, thank you again! |
It may be worth trying to figure out what goes wrong with The transition period towards ES6 import/export that JS and node.js are in right now can be really confusing. A const foo = require('foo') is equivalent with: import * as foo from 'foo' The line: math.import(require('mathjs/lib/type/fraction')) Should be come something like (not tested): import * as fraction from 'mathjs/lib/type/fraction'
math.import(fraction) |
I agree that ES6 import is very confusing!!!
I just tried above code, but didn't work. I think I'd better just move on, at least, I got the correct results by using mathjs (but not fraction.js). Thank you very much, Sir, for trying to help me!!! |
👍 |
I just used the part of "fraction" from mathjs for my class project, and only two lines of code as below:
It works perfectly! Thanks a lot for mathjs!!!
However, my final
bundle.js
is 642KiB that is much bigger than my instructor's 125KiB.My instructor used
Fraction.js
rather thanmathjs
.Thus, I guess the huge different size of
bundle.js
because mathjs is much bigger than Fraction.js?I would like to know if I can import a small part of mathjs for
fraction
only? And how to do it?The text was updated successfully, but these errors were encountered: