Git Product home page Git Product logo

child's Introduction

Framework for bulding libraries for both browser and NodeJS

Commands

  • npm login
  • npm publish - to publish / update a package
  • npm unpublish [package_name] - to delete

Framework structure

The purpose of this boilerplate/framework is to quickly enable you to start developing NodeJS and Browser libraries.

It allows you to write code in the form of Typescript that will be compiled in JavaScript es6.

As a starting point, it's assuming that the library will require to send requests using the fetch API in the browser and a custom library like node-fetch in NodeJS.

The output will be placed inside dist folder and it's represented by the following files.

  • browser.js the output for browser (this file must be imported for a browser scenario)
  • node.js the output for NodeJS (this file must be imported for a NodeJS scenario)
  • main.js the common code between them
  • *.d.ts - declaration for browser,main and node js

!

The toolchain will not bundle the node_modules libraries. They are ommited using externals: [nodeExternals()] property in webpack.config.js,

As an example for this behavior node-fetch was installed. You can run npm run build:prod and inspect the code from index.js.

!

Source Mapping is enabled in webpack for development environment with cheap-module-source-map option by default.

You can modify it with your desired value


Webpack

Webpack exposes two config objects nodeConfig and browserConfig. Both of them extend generalConfig.

The configuration was inspired from their documentation.

! The library is exported as default

Browser

In a browser scenario where the library will be added using a script tag, then the code will bind to global object window using the name from browserConfig.output.library. In this case MyLibrary.


Testing

For testing, Jest is configured and contains a dummy example.

Jest

npm run test npm run test:watch npm run test:cov


Publishing

  • Build before publish and expose the files for a more appealing import - you can add this property inside package.json in scripts object, if you need a hook before you publish your package. This command will be executed when you run npm publish, but before publishing the code.

    "prepublishOnly": "webpack --mode=production && npm run expose",
  • Versioning - each time you run npm publish, be sure to update the version in "version": "1.0.0" property inside package.json. Otherwise you won't be able to deploy a new version.

  • Ignoring files - use .npmgignore in the same way as .gitignore, but for npm

!

No value for the properties main, types or files was specified in package.json, because here there is no main file, but rather two main files each one for a specific env.

The library must be imported

require("library/dist/node");

child's People

Contributors

shivansh-cg avatar

Watchers

 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.