Bundlers
Examples of Warp SDK usage with different web bundlers (webpack, parcel, vite, rollup) and with .ts/.js/.mjs files in Node.js
Install / Use
/learn @warp-contracts/BundlersREADME
Bundlers
Warp bundlers repository aims to provide sample projects using Warp SDK within diferent web and server bundles. Due to various implementation of bundlers, each of these projects need to meet specific requirements which are described in this readme.
If you encounter any issues while using Warp SDK in a specific bundler (due to upgraded version etc.), please create an issue in the repository.
You can find helper scripts in the root package.json file, you can use either yarn or npm. For each of the project we are testing deploying the contract, writing interaction and reading the state.
Web bundlers scripts
- Install dependencies
yarn install:[PROJECT_NAME]
- Start development server
yarn start:[PROJECT_NAME]
- Build for production
yarn build:[PROJECT_NAME]
Server scripts
- Install dependencies
yarn install:node
- Build typescript files and run all server scripts (
.mjs,.js,.ts, usingts-nodeinstead of regularnodescript)
yarn run:node
Web bundlers - Next - Parcel - Rollup - Unpkg - Vite - Webpack 4 - Webpack 5
Server - Node
Next
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { defaultCacheOptions, WarpFactory } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration:
In order for production deployment to work properly, it is needed to set swcMinify property to false. Please refer to this github issue to see the reason for applying this change.
const nextConfig = {
swcMinify: false,
};
Parcel
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { defaultCacheOptions, WarpFactory } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration: Not required.
Rollup
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { defaultCacheOptions, WarpFactory } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration: Not required.
Unpkg
Directory: Refer to this directory to see the bundler configuration. You can use either full or minfied version of the Warp SDK, check out this section to view possible options.
Usage:
Insert script tag in your index.html file:
<script src="https://unpkg.com/warp-contracts@1.2.0-bundles.16/bundles/web.iife.bundle.min.js"></script>
const sdk = warp.WarpFactory.forMainnet();
Additional configuration:
- In order for Typescript project to work properly, you need to extend
Windowtype bywarp. You have few options to choose from, eg.:
const warp = window['warp'];
or
const warp = (<any>window).warp;
- Remember to set
isolatedModulesproperty tofalseincompilerOptionsin yourtsconfig.jsonfile.
Vite
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { defaultCacheOptions, WarpFactory } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration: Not required.
Webpack 4
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { WarpFactory, defaultCacheOptions } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration:
- In order for Typescript project to work properly, you need to set
strictproperty tofalsein thecompilerOptionsin yourtsconfig.jsonfile. You can also add//@ts-ignoreabovewarp-contractsimport.
Webpack 5
Directory: Refer to this directory to see the bundler configuration.
Usage:
import { WarpFactory, defaultCacheOptions } from 'warp-contracts';
const warp = WarpFactory.forMainnet();
Additional configuration:
- In order for Typescript project to work properly, you need to set
strictproperty tofalseandmoduleResolutiontonodenextin thecompilerOptionsin yourtsconfig.jsonfile. You can also add//@ts-ignoreabovewarp-contractsimport.
Node
For server side we are testing
CommonJSversion in a.jsfileECMAScriptversion in a.mjsfileTypescript- in a
.jsfile compiled withtsccommand - directly in a
.tsfile executed withts-nodeexection machine
- in a
