d4nyll / lethargy

Distinguish between scroll events initiated by the user, and those by inertial scrolling
http://d4nyll.github.io/lethargy/
MIT License
556 stars 47 forks source link

Errors with import/require with webpack #21

Closed josephahern closed 6 years ago

josephahern commented 6 years ago

Hi,

I am attempting to use your plugin with webpack and am using this way:

import Lethargy from 'lethargy/lethargy.min';

export default class Scrolljack {

    constructor(el) {
        this.el = $(el);
        this.lethargy = new Lethargy();
    }
    init() {
        console.log(this.lethargy);
    }
}

// main.js
import Scrolljack from 'scrolljack.js'
const scrolljack = new Scrolljack();
scrolljack.init();

But I am running into the following issue:

lethargy2.default is not a constructor

when I use require, I get the following:

Lethargy is not a constructor

Is there a preferred / suggested way of including into a project?

josephahern commented 6 years ago

And today I learn of exports loader!

Here is the solution:

npm install exports-loader
const Lethargy = require("exports-loader?this.Lethargy!lethargy/lethargy");
d4nyll commented 6 years ago

@josephahern Thanks for this. I will add a note in the README.md!

borm commented 4 years ago
this.Lethargy!../node_modules/lethargy/lethargy.js)
Module build failed (from ../node_modules/exports-loader/dist/cjs.js):
ValidationError: Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema.
 - options misses the property 'exports'.
cjpearson commented 3 years ago

For exports-loader 2, this syntax seems to work. const Lethargy = require('exports-loader?type=commonjs&exports=single|this.Lethargy!lethargy/lethargy');