I use Laravel Mix for compiling JS files. I want to move all my functions to another file named functions.js. In app.js I want to include this file.

functions.js

var functions = {
  test: function() {
    console.log('test');
  }
}
exports = functions;

app.js

import functions from './functions';
functions.test();

Message From Console

Uncaught TypeError: _functions__WEBPACK_IMPORTED_MODULE_3___default.a.test is not a function

1 Answers

2
Cyro Farias On Best Solutions

functions.js

    module.exports = {
        test: function () {
            console.log('test');
        }
    }

app.js

  import functions from './functions';

  functions.test();

OR:

functions.js

const test = () => console.log('test');
const test2 = () => console.log('test2');

module.exports = { test, test2 };

app.js

import functions from './functions';

functions.test();
functions.test2();