Giter Club home page Giter Club logo

lazyload-es2015-webpack-test's Introduction

lazyload-es2015-webpack-test

Test usage of LazyLoad as es2015 module in a WebPack build.

Installation

Install LazyLoad with the command

npm install vanilla-lazyload

Or install a specific version with

npm install vanilla-lazyload@{{version}}

Usage

The best solution which works out of the box is to use the ES6 module syntax (aka ESM), and import LazyLoad like the following:

import LazyLoad from "vanilla-lazyload";

const lazyLoadOptions = {/* your options here */};
const pageLazyLoad = new LazyLoad(lazyLoadOptions);

See lazyload-init.js for an example, or go to LazyLoad's readme file for documentation.

If using the ESM syntax isn't possible for you and you wish to continue using the CJS require syntax, read usage as CommonJS module below.

Build

Configure the build script in your package.json like the following:

{
	"scripts": {
		"build": "webpack"
	}
}

Then, in your terminal, run:

npm run build

Result

To see the result, open the dist/index.html file.

That's it!


Usage as CommonJS module

In case you want to import LazyLoad using the require directive, you must configure WebPack to load the scripts from the package.json's main fields instead. More info.

So edit your webpack.config.js file and add or edit the resolve.mainFields setting to ["main", "browser", "module"] like follows:

module.exports = {
	// other configuration fields here
	resolve: {
		mainFields: ["main", "browser", "module"]
	}
};

This tells WebPack to resolve your requires to the packages main field, which must contain contains the UMD version of the installed modules. More info.

For an example usage, see the commonJS branch on this very repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.