Giter VIP home page Giter VIP logo

es6-lib's Introduction

es6-lib

This project illustrates how a library written in es6 can be published supporting tree shaking. I intentionally created a minimal React component library as it involves some extra configuration than a simple tiny module.

The library in the src directory is written in es6 using the import and export syntax. The project that uses this library can be found in the test directory.

The library is bundled with rollup. The rollup configuration uses babel to create an es module using the import and export syntax.

The project is bundled with webpack as it is meant to run as a stand-alone application in the browser. The webpack configuration has a specific optimization configuration to create separate bundles for vendor libraries and webpack runtime code. This optimization configuration is not needed, and it is only used in this case to isolate the code that is produced for the index.js file.

How to test it yourself

Clone the project and install and build the library:

yarn install && yarn build

Then navigate to the test directory and install and build the project:

cd test && yarn install && yarn build

Notice that the webpack output will contain something like the following:

index.js  221 bytes       0  [emitted]  index

Now if we import and use the Input component in ./test/src/index:

import React from 'react';
import { render } from 'react-dom';
import { Button, Input } from 'es6-lib';

render(
  <div>
    <Button />
    <Input />
  </div>,
  document.getElementById('root')
);

and run yarn build again, we'll notice that the size of the index.js file increased.

index.js  279 bytes       0  [emitted]  index

That is because webpack now imported the code for the Input component as well. In the previous build, webpack didn't include the code for the Input component from the es6-lib package, as we were not using it.

es6-lib's People

Contributors

spirosikmd avatar

Watchers

 avatar  avatar

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.