mathjs-webpack-loader

0.1.0 • Public • Published

mathjs-webpack-loader

loader for mathjs parsed expression

Installation

npm install --save-dev mathjs-webpack-loader && npm install --save mathjs

Usage

expressions.mathjs

x^2 + x/4 + 3*y
x + y

webpack.config.js

module.exports = {
    module: {
        rules: [
            {
                test: /\.mathjs?$/,
                loader: 'mathjs-webpack-loader'
            }
        ]
    }
};

index.js

import expressions from 'expressions.mathjs';
import mathjs from 'mathjs';
 
const instance = mathjs.create();
const compiled = expressions(instance).map(exp => exp.compile());
 
console.log(compiled[0].eval({x: 4, y: 1})); // 20
console.log(compiled[1].eval({x: 1, y: 1})); // 2

If only one expression contains in *.mathjs file, then it will be return instead of array. Loader returns function which contains only one parameter - mathjs instance, see configuration.

Steps to run example

  • fork or clone repository
  • npm install
  • npm run build-example
  • View example/bundle.js or example/index.html in browser

Readme

Keywords

none

Package Sidebar

Install

npm i mathjs-webpack-loader

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

4.11 kB

Total Files

4

Last publish

Collaborators

  • vankop