loader for mathjs parsed expression
npm install --save-dev mathjs-webpack-loader && npm install --save mathjs
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})); // 2If 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.
- fork or clone repository
npm installnpm run build-example- View
example/bundle.jsorexample/index.htmlin browser