简体   繁体   中英

How to import a plugin using ES6? (Getting ReferenceError: Plugin is not defined)

Trying to wrap my head around Webpack. I was able to set it up and get it working (combines my scripts and styles just fine), but I'm having trouble with a lazy loading plugin called bLazy, which I installed via npm. Here's the code in the file that I've defined as the entry point:

// Stylesheets

import './style.scss';

// Scripts

import 'salvattore'; 
import 'blazy'; 

var bLazy = new Blazy(); // This is the documented way to initialize bLazy.

I am getting the error: Uncaught ReferenceError: Blazy is not defined . The Salvattore plugin, which is self-initializing, works fine. I'm also using jQuery, but bLazy is written in Javascript, so there shouldn't be any conflicting issues.

What am I doing wrong?

+++ UPDATE +++

I've changed the way I posed my question because apparently it's about ES6 and not Webpack, like I thought it was.

喜欢这个import Blazy from 'blazy'

In the script you want to import you should "export" a value, like this:

class Blazy {...}

export default Blazy;

Then in script where you want to use it, you need to "import" this value:

import Blazy from './blazy'; // Note the path in quotes is relative to your current script file

let blazy = new Blazy();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM