Moenchfracht's avatar

Webpack app.js, bootstrap.js and so on...

Hi there! I'm struggling with javascripts in my laravel app. I want to include instructorjs (https://www.npmjs.com/package/instructorjs), but it doesn't work. I think that script loading as modules doesn't work in combination with webpack. But I don't know where and how to import the scripts. I ended up with:

import {jqueryScrollTo} from '/node_modules/jquery.scrollto/jquery.scrollTo.min.js';
import {InstructorFactory} from '/node_modules/instructorjs/instructor.min.js'
jqueryScrollTo(window.$);

window.jqueryScrollTo = require('jquery.scrollto');
window.InstructorFactory = require('instructorjs');

in my bootstrap.js. In my view I have these lines:

const instructorFactory = require ('instructorjs');
var instructor = new instructorFactory();

My webpack.mix.js lines are:

mix.js('resources/js/app.js', 'public/js').sourceMaps().extract()
    .sass('resources/sass/app.scss', 'public/css')
    .autoload({ jquery: ['$', 'jQuery', 'window.jQuery']});

Any help from you is very appreciated! :)

Btw I just crossposted my question on SO: https://stackoverflow.com/questions/71479830/use-npm-javascript-module-with-webpack-mix

0 likes
0 replies

Please or to participate in this conversation.