GithubHelp home page GithubHelp logo

krasimir / webpack-library-starter Goto Github PK

View Code? Open in Web Editor NEW
1.4K 34.0 294.0 605 KB

Webpack based boilerplate for producing libraries (Input: ES6, Output: universal library)

License: MIT License

JavaScript 61.80% HTML 32.68% TypeScript 5.51%

webpack-library-starter's Introduction

Webpack library starter

Webpack based boilerplate for producing libraries (Input: ES6/TypeScript, Output: universal library)

Features

  • Webpack 5 based.
  • ES6 or TypeScript as a source.
  • Exports in a umd format so your library works everywhere.
  • Test setup with Jest.

Process

ES6/TypeScript source files
       |
       |
    webpack
       |
       +--- babel
       |
  ready to use
     library
  in umd format

Have in mind that you have to build your library before publishing. The files under the lib folder are the ones that should be distributed.

Getting started

  1. Setting up the name of your library
  • Open webpack.config.js file and change the value of libraryName variable.
  • Open package.json file and change the value of main property so it matches the name of your library.
  1. Build your library
  • Run yarn install (recommended) or npm install to get the project's dependencies
  • Run yarn build to produce minified version of your library.
  1. Development mode
  • Run yarn dev. This command will generate a non-minified version of your library and will run a watcher so you get the compilation on file change.
  1. Running the tests
  • Run yarn test

Scripts

  • yarn build - produces production version of your library under the lib folder
  • yarn build-amd - produces an AMD version that works with RequireJS
  • yarn dev - produces development version of your library and runs a watcher
  • yarn dev-amd - produces an AMD development version of your library and runs a watcher
  • yarn test - well ... it runs the tests :)
  • yarn test-watch - same as above but in a watch mode

Readings

Misc

An example of using dependencies that shouldn’t be resolved by webpack, but should become dependencies of the resulting bundle

In the following example we are excluding React and Lodash:

{
  devtool: 'source-map',
  output: {
    path: '...',
    libraryTarget: 'umd',
    library: '...'
  },
  entry: '...',
  ...
  externals: {
    react: 'react'
    // Use more complicated mapping for lodash.
    // We need to access it differently depending
    // on the environment.
    lodash: {
      commonjs: 'lodash',
      commonjs2: 'lodash',
      amd: '_',
      root: '_'
    }
  }
}

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.